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

John H
John H used Ask the Experts™
on
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!!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hi John,

you almost done it.
Try
if  ( !has_tag() ) { echo 'This page has no tags; please add tags in the comments section' ; }

Open in new window

John HGeneral Tinkerer

Author

Commented:
Awesome Dmitri - It works!!  Just needs to be styled a bit - Thank You Much!
John HGeneral Tinkerer

Author

Commented:
Quick question Dmitri - I'm editing the core files of the parent theme.  Should I have used a function in the childtheme instead?  Thx.

Commented:
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.)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial