Hello,
I am looking to render some HTML code inside module blocks when a certain tag is assigned to a post.
I’ve gotten this snippet working inside loop-single-2.php by adding:
<?php if ( has_tag( 'promoted-content' ) ) : ?>
<h3 class="promoted-txt">Promoted Content</h3>
<?php endif; ?>
However, when I add this same snippet to td_module_2.php right under the <?php echo $this->get_title();?>, I get nothing outputted to the screen, even though the ‘promoted-content’ tag is assigned to that post.
How do I get the has_tag() condition to work on these td_module_X.php files? What is the correct syntax to trigger it to work?
See attached screenshots. The first shows the modules blocks I need to render the conditional HTML, and the second screenshot shows a very simple example of how I want it to look just so you know understand my goal.
Note: I am not asking you to help me with the HTML or CSS. I simply need the correct syntax for the has_tag( ‘promoted-content’ ) snippet that will trigger the HTML to output on the frontend.
Thank you for your help.


Hi,
Try it like this, seems to work properly
– https://www.screencast.com/t/zGy37CT75liq
– https://www.screencast.com/t/cMC0e2F3
<?php if ( has_tag( 'promoted-content', $this->post->ID ) ) : ?> <h3 class="promoted-txt">Promoted Content</h3> <?php endif; ?>
Thanks
Thanks for your quick response. Your solution does in deed work for /includes/modules/td_module_2.php and td_module_6.php (which is an extension of module_2 I believe) so thank you for that!
What files would I edit for the Slide Block and Big Grid 1, and would I use the same syntax you provided?
Ok, I figured out the Big Grid 1, but the Slide has me stumped. When I open up the td_module_slide.php, I don’t see anywhere I can place the <?php if ( has_tag( 'promoted-content', $this->post->ID ) ) : ?> <h3 class="promoted-txt">Promoted Content</h3> <?php endif; ?>
Can you please help me with this last module?
Hi,
That may not be so easy, the slide is a complex element. You could try to integrate the condition where there are other conditions, then check the results
– https://www.screencast.com/t/ztgzk4bJG
You can keep testing but it will probably not be easy.
Thanks