Archived topic
Conditional code in hook
10 replies · Started by Aaron on September 11, 2017
I've just started trying to write php and am trying to enter a shortcode after content for one category. Here's what I have:
<?php if ( is_category( 'hearing' ) ) : ?>
<?php echo do_shortcode( ' [elementor-template id=“701”] ' ); ?>
<?php endif; ?>
But I cannot get it working.
Any idea what I'm doing wrong?
Hi there,
Are you wanting it to show up after the single post content, or on the category archive page?
Hi Tom.
Single posts only.
Thanks for the quick response.
Try this instead:
<?php if ( in_category( 'hearing' ) ) : ?>
<?php echo do_shortcode( '[elementor-template id="701"]' ); ?>
<?php endif; ?>
That's working now. But it's also showing up on the archive page for that category.
Got it. Had to add && is_single().
Phew. I really wish conditional statements were easier. Thanks, Tom.
Glad I could help :)
Hi Aaron or Tom, Could you please post the whole code with the && is_single() ammendement? Thanks !
This should be it:
<?php if ( in_category( 'hearing' ) && is_single() ) : ?>
<?php echo do_shortcode( '[elementor-template id="701"]' ); ?>
<?php endif; ?>
Hi thanks for the swift response :D
----EDITED and opened a new topic-----
Thanks for assistance
Mikel
Can you open a new topic for your questions? Thanks!