Trying to tweak the HTML around the category tag
-
Hi Mr. Ercikson,
thanks again for your awesome work with this Plugin!
Right now I am trying to tweak the HTML around the category tag. I want to change the
<a>
to a<span>
and replace thehref="xyz.tdl/this-slug"
with adata-slug="this-slug"
I thought of somehow tweaking it in a codesnippet with a
display_posts_shortcode_output
filter. I already managed it to add meta values from ACF, perfekt!I then found the way to strip the whole html around the tags and cats, which works, but looses the possibility to tweak CSS per single term:
add_filter( 'display_posts_shortcode_category_display', 'strip_tags' );
After all i found a way to apply filters, but i don’t know how to use them properly.
https://github.com/billerickson/display-posts-shortcode/issues/185In the code to the plugin itself i found the passage:
$category_display_text = ''; if ( $category_display && is_object_in_taxonomy( get_post_type(), $category_display ) ) { $terms = get_the_terms( get_the_ID(), $category_display ); $term_output = array(); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $term_output[] = '<a href="' . get_term_link( $term, $category_display ) . '">' . $term->name . '</a>'; } $category_display_text = ' <span class="category-display"><span class="category-display-label">' . $category_label . '</span> ' . implode( ', ', $term_output ) . '</span>'; } $category_display_text = apply_filters( 'display_posts_shortcode_category_display', $category_display_text, $terms, $category_display, $original_atts ); }
I thought of somehow tweaking it in a codesnippet with a
display_posts_shortcode_output
filter like that (what sadly didn’t worked):$category_display_text = ''; if ( $category_display && is_object_in_taxonomy( get_post_type(), $category_display ) ) { $terms = get_the_terms( get_the_ID(), $category_display ); $term_output = array(); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $term_output[] = $term->name; } $category_display_text = $category_label; } $category_display_text = apply_filters( 'display_posts_shortcode_category_display', $category_display_text, $terms, $category_display, $original_atts ); }
Thank you for reading all this and I hope that there is a way you could help me.
Kind regards,
Marius
- The topic ‘Trying to tweak the HTML around the category tag’ is closed to new replies.