Hello,
Beans is growing on me, but I feel like we have to ask a lot of questions in the forum because the documentation doesn't have a lot of practical examples.
How would I remove the separator between the categories and tags? By default it is a comma. I can't find a way to target this specific part.
Also, how could I wrap each category in a different div? So that it would be something like this: Categories:
<div>Cat1</div><div>Cat2</div>
Hi Olaf,
Beans uses WordPress Core functions where possible, for instance it uses get_the_category_list()
and get_the_tag_list()
to display the post categories and tags. Below is a snippet using the WP Core filters to replace the comma separators with spaces:
add_filter( 'the_category', 'example_categories_output', 10, 2 );
/**
* Modify the list of categories.
*
* @param array $thelist List of categories for the current post.
* @param string $separator Separator used between the categories.
*
* @return string The list of categories.
*/
function example_categories_output( $thelist, $separator ) {
return str_replace( $separator, ' ', $thelist );
}
add_filter( 'the_tags', 'example_tags_output', 10, 3 );
/**
* Modify the list of tags.
*
* @param string $tag_list List of tags.
* @param string $before String to use before tags.
* @param string $sep String to use between the tags.
*
* @return string The list of tags.
*/
function example_tags_output( $tag_list, $before, $sep ) {
return str_replace( $sep, ' ', $tag_list );
}
Happy coding,