Archived topic
Conditional Hook
3 replies · Started by Dan on July 11, 2019
HI
Any idea why this is not working? (located in functions.php)
if ( is_single() ){
add_action( 'generate_after_main_content','ds_recent_articles' );
function ds_recent_articles() {
echo do_shortcode('[wp_show_posts id="422"]');
}
}
Without the condition it works, but then displays the posts on all pages.
Thanks
Dan
Hi there,
First of all just want to make sure you are referring to child theme's function.php.
The code isn't working as the conditional tag needs to be inside the function itself like this:
https://generatepress.com/forums/topic/modify-image-size-name-on-single-php/#post-944686
That can also be done using our hooks element as well without any coding:
https://docs.generatepress.com/article/hooks-element-overview/
Thanks Leo.
Moving the conditional into the function fixed the issue.
This site specifically doesn't have GP premium, so a hook inside functions.php had to do.
Thanks again for your great support, much appreciated.
Dan
No problem :)