HTML comment block vs. php conditional content #39409
eningan
started this conversation in
Developer Experience
Replies: 1 comment
-
|
Hi, The Post Terms block (Categories, Tag) calls In other words, it passes through the following filter hooks:
There does not appear to be a way to add your own class name to the a element in these hooks, but you may be able to accomplish something similar with the following: add_filter('get_the_terms', function( $terms, $post_id, $taxonomy ) {
$new_terms = array();
foreach ( $terms as $term ) {
if ( 'some-rule' === $term->slug ) {
$term->name = '<span class="some-icon-classes">' . $term->name . '</span>';
}
$new_terms[] = $term;
}
return $new_terms;
}, 10, 3 ); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am currently trying to update an old theme to the 5.9 version (FSE).
I'm stuck on a concept, the transition from PHP pages to HTML pages.
Concretely, I am trying to replace the name of my category with an icon.
In PHP I could include conditional code that checked the category of the post and I could change the content of the link (in the taxonomy-category div) to an image.
Can you explain to me the method to reproduce the following code with the new HTML blocks?
In my single.ph file :
In the single.html file :
<!-- wp:post-terms {"term":"category"} /-->It's obviously possible to do with javascript, even with a hook in the functions.php file but I would have liked to keep it in the single.html file.
What is the best method, a filter, a pattern ... ?
In general I would like to know how to modify the result generated by the HTML comment blocks (can we make personalized arguments?).
As I'm a bit lost, I hope my question is clear.
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions