We help IT Professionals succeed at work.

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

John H
John H asked
on
166 Views
Last Modified: 2017-03-27
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

consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
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.
Dmitriiconsultant
CERTIFIED EXPERT

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