[Resolved] Correct PHP syntax for conditional hook

Home Forums Support [Resolved] Correct PHP syntax for conditional hook

Home Forums Support Correct PHP syntax for conditional hook

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #246841
    Lyle

    Hi Tom.

    In this topic, https://generatepress.com/forums/topic/hook-question , you posted some PHP for excluding a number of pages for the display of a shortcode. Works fine πŸ™‚

    However, I am using the following to do something similar, except this is to display one shortcode on a couple pages and another on one page. The code below works fine in the GP Hooks but I am a bit puzzled (doesn’t take much πŸ™‚ ) about the syntax when compared to yours. Yours has more PHP tags enclosing the echo statements, etc. I found the syntax I used on Stack Overflow, so I am just wondering if it is ‘legit’ πŸ™‚

    <?php
    if ( is_page( array( 'services', 'about'  ) ) ) {
        echo do_shortcode( '[INSERT_ELEMENTOR id=115]' );
    } else {
        echo do_shortcode( '[INSERT_ELEMENTOR id=21]' );
    }
    ?>

    Cheers!
    Lyle

    #246866
    Tom
    Lead Developer
    Lead Developer

    Nothing wrong with that at all.

    I think the only difference is I used ! as in “do not include” on these pages.

    Your syntax looks good πŸ™‚

    #246869
    Lyle

    Thanks, Tom πŸ™‚

    Yep, the ! (not) is one of the very few PHP operators I do know πŸ™‚

    Just wanted to make sure as I am about to create a tutorial based upon this to show how to switch page headers in the GP Theme that have been created with Elementor by placing this in the GP Hooks Before Header Content hook location. Works slick πŸ™‚

    Cheers!
    Lyle

    #246874
    Tom
    Lead Developer
    Lead Developer

    Awesome! πŸ™‚

    #246879
    Lyle

    Here it is πŸ™‚

    Here is one that will get your GeneratePress/GP Premium “thinking cap” in a twirl πŸ™‚

    How does switching your site header based upon the page name sound to you?

    Thought so. Enjoy πŸ™‚

    http://snifflevalve.com/tutorials/elementor-generatepress-gp-premium-anywhere-elementor-switch-site-header/

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