Support » Fixing WordPress » tags separated by commas, not reflecting “the_tag” by space

  • arsm

    (@arsenalemusica)


    I learned that the_tag is the core thing that makes tags/categories separated by whatever character one chooses. I checked my theme and all references are like the_tags( '' ), i.e. with a blank space, which is what I want.
    So why is the site showing them all separated by commas?

    It’s the same if I look at get_the_category_list( ', ', '', get_the_ID() )
    (as per codex) and see that it indicates a blank space, not a comma. So how do I eliminate that comma?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    '' is not the same as ' '. Try putting a space between the primes.

    Thread Starter arsm

    (@arsenalemusica)

    ok, so it’s not the same… but now I guess I have to change every instance of the_tags and get_the_category_list in every file that I find them, because I can’t figure out which template belongs to which page. Is it a correct procedure?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    No. You could write a filter to change how tags are returned. https://developer.wordpress.org/reference/hooks/the_tags/

    Thread Starter arsm

    (@arsenalemusica)

    writing code is beyond my skills… however, it says that the filter is for a given post. But I’d need to apply it globally, i.e. for every posts/cpts and for every page that outputs them. Am I right?

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    Yes, trivial.

    A filter is pretty much global.

    Thread Starter arsm

    (@arsenalemusica)

    hello again, I found a filter that sound like the one I need… but it’s not working
    caould you tell me what can be wrong with this:

    add_filter( 'the_tags', 'example_tags_output', 10, 3 );
    function example_tags_output( $tag_list, $before, $sep ) {
     return str_replace( $sep, ' ', $tag_list );}
    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    do a bit of debugging. What’s $sep? What’s in $tag_list?

    Thread Starter arsm

    (@arsenalemusica)

    🙂 I actually was wrong from the start, because I meant to separate categories that are output as tags (yet, I need to separate tags as well, and the place I ripped that code off offers both).
    About your question, maybe $sep should be replaced by $separator, and $tag_list should be the name that my theme uses?
    Sorry, but I’m not coder, I’just guessing… with your help.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    I added the code you listed above

    add_filter( 'the_tags', 'example_tags_output', 10, 3 );
    function example_tags_output( $tag_list, $before, $sep ) {
     return str_replace( $sep, ' ', $tag_list );}

    to my test site’s theme’s functions.php and the tags at the bottom of the post went from comma separated to space separated, so that code works.

    Thread Starter arsm

    (@arsenalemusica)

    I have tried all possible tweaks but that code (or any other code) don’t work for me. Would you be so kind to look at this page and tell me how to get rid of that commas between categories?
    (I’m putting the site off maintenance for a while, and the page will open slowly because I have to improve the search results).

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    If that code doesn’t work, contact the developers of your theme. My test, with twentytwentyone, shows it does.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.