Link to home
Start Free TrialLog in
Avatar of John H
John HFlag for United States of America

asked on

Wordpress - Adding an if/else Conditional Argument in a Post Template

Hi All,

I have a Wordpress site that relies on posts having tags - its important to the categorization of the site.

I'd like to drop in a conditional argument in single.php such that if the post has no tags, that it echoes some content on the post (essentially, asking site visitors to suggest some tags in the comments section that i can later update the post with).

This code is not correct, but I hope it captures the essence of what I'm trying to do

	<?php if ( has_tag('none/null' ) { echo 'This page has no tags; please add tags in the comments section' ; } else { echo '' ; } ; ?>

Open in new window

Thanks in advance!!
Avatar of Dmitrii
Flag of Russian Federation image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John H


Awesome Dmitri - It works!!  Just needs to be styled a bit - Thank You Much!
Avatar of John H


Quick question Dmitri - I'm editing the core files of the parent theme.  Should I have used a function in the childtheme instead?  Thx.
Yes, surely.
Otherwise you will lost all your changes after upgrade of your parent theme.
(And upgrades are vital as they may deal with security.)