• Hello WordPress community.

    I have a question. I’m using the_tag() function for displaying tags in my posts. Is it possible for me to make it automatically display as ‘No Tags’ when no single tag is inserted? Anyone knows how to make it possible?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I think something like this would work:

    if (the_tags('Tags:','','') === false) echo 'No Tags';

    Thread Starter fath

    (@fath)

    Hi Otto42,
    I have tried it but no difference. Still not displaying anything.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Ahh well… This should do it then:

    if (empty(get_the_tags()) echo "No Tags";
    else the_tags('Tags:');
    Thread Starter fath

    (@fath)

    Thanks. But, can you show me how should the complete code looks like? It’s kinda confusing…

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    What “complete code” are you talking about?

    Just stick what I gave you into your theme wherever you want to display the tags.

    Thread Starter fath

    (@fath)

    Done it. But whenever I refresh my website to see the result, blank page appears. Check out https://www.owastudio.com and see whether you can open the website properly…

    Thread Starter fath

    (@fath)

    Sorry, have to replaced with normal the_tags() because people complaining they can’t visit my website. But that’s what happened. Once I put in the above code, my website just showing a blank page.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Ahh, I left off a closing parentheses. Try this new code.

    if (empty(get_the_tags())) echo "No Tags";
    else the_tags('Tags:');

    this forum needs a built-in debugger ??

    (or at least syntax highlighting!)

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    (or at least syntax highlighting!)

    !!!!!

    Yes!

    Thread Starter fath

    (@fath)

    Haha. By the way, i paste the new code and still having blank page. Weird?

    For the code Otto42 gave above, I think you would need to add php opening and closing around it, or paste it somewhere that’s already in php.

    This code below shows “No Tags here” for posts without a single tag, then it shows the posts that have tags (post title followed by the list of tags). This also illustrates the opening php, IF statement, ELSE statement, and closing php. That can be useful.

    <?php
    $tag = get_the_tags();
    if (! $tag) { ?>
    <p>No tags here. <a href="<?php the_permalink() ?>" rel="bookmark" title="Entry for <?php the_title(); ?>"><?php the_title(); ?></a></p>
    
    <?php } else { ?>
    
    <p>Tags here for <a href="<?php the_permalink() ?>" rel="bookmark" title="Entry for <?php the_title(); ?>"><?php the_title(); ?></a> -  <?php the_tags(' ', ' | ', ''); ?></p>
    
    <?php } ?>
Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Displaying ‘No Tags’ when no single tag is inserted’ is closed to new replies.