Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post terms: Add a CSS class to identify the taxonomy #31832

Merged
merged 2 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-library/src/post-terms/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function PostTermsEdit( {
const blockProps = useBlockProps( {
className: classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
[ `taxonomy-${ term }` ]: term,
} ),
} );

Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/post-terms/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
return '';
}

$align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
$classes = 'taxonomy-' . $attributes['term'];
if ( isset( $attributes['textAlign'] ) ) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
carolinan marked this conversation as resolved.
Show resolved Hide resolved
}

$terms_links = '';
foreach ( $post_terms as $term ) {
Expand All @@ -37,7 +40,7 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
);
}
$terms_links = trim( $terms_links, ' | ' );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

return sprintf(
'<div %1$s>%2$s</div>',
Expand Down