[Resolved] Conditional Hook

Home Forums Support [Resolved] Conditional Hook

Home Forums Support Conditional Hook

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #955141
    Dan

    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

    #955146
    Leo
    Staff
    Customer Support

    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/

    #955228
    Dan

    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

    #955310
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.