Why isn’t is_page working when I put it in the functions.php file?

I have page called “Apple”, the page’s ID id 2533. In page.php file I have line: echo $bannerimg And this function in functions.php: if ( is_page( ‘2533’ ) ) { // also tested with ‘Apple’ $bannerimg = ‘apple.jpg’; } elseif ( is_page( ‘test’ ) ) { $bannerimg = ‘test.jpg’; } elseif ( is_page( ‘admissions’ ) … Read more

Loading scripts only if a particular shortcode or widget is present

I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on http://wpengineer.com function has_my_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( … Read more

wp enqueue style on specific page templates

I am in the process of a theme, I would like to add landing pages using page-templates. I cannot find anywhere that shows how to enqueue style or js for specific page templates. Any suggestions. Ex. Landing Page 1 – landing-page-template-one.php will need very different style and js than the blog or homepage. 6 If … Read more

Enqueue Scripts / Styles when shortcode is present

What is the idea way to register/enqueue scripts and/or styles for use in plugins? I recently made a plugin simple plugin to add the user avatar/gravatar with a shortcode. I have different style options for displaying the avatar (square, round, etc.) and decided to put the css directly in the shortcode itself. However, I realize … Read more