Archived topic
Correct PHP syntax for conditional hook
4 replies · Started by Lyle on November 22, 2016
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
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 :)
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
Awesome! :)
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 :)