Articles of conditional tags

functions.php conditional tag – only show in single.php?

//Geo Map add_action( ‘woo_post_inside_after’, ‘my_geo_mashup’ ); function my_geo_mashup() { global $post; if ( in_category(‘listings’) ) { echo GeoMashup::map(); } } Works to embed my map tag only on my single posts categorized as “listings” But, the embedded tag is also showing within the index of posts (thumb, title, meta, excerpt) and I need to remove […]

using conditionals on enqueue styles

I want to run my css code on a specific page in admin area. What is the best approach please? A: function register_style() { if (is_page..something) { wp_enqueue_style(‘style’, PLUGIN_URL . ‘style.css’); } } add_action(‘admin_enqueue_scripts’, ‘register_style’); B: function register_style() { wp_enqueue_style(‘style’, PLUGIN_URL . ‘style.css’); } if (is_page..something) { add_action(‘admin_enqueue_scripts’, ‘register_style’); }

if custom posts type exists and there are posts load script

I have registered a custom post type ‘featured_post’. I am looking for a way to test if the blog home page has any ‘featured_post’ posts on it and if it has load a javascript file. The ‘featured_post’ posts will make a slider at the top of the blog home page. I had this working using […]

Change Site Title and Description html tags if not home page

For the purpose of good HTML structure, accessibility and SEO I’d like to change the site’s title and description from H1 and H2 to P when appearing on any page other than the homepage. A conditional statement logic would be something like; when not homepage change site title and description to Site Title and Description […]

Conditional tags inside a class

I have a couple of functions that I now combined in a class. The reason for that was that all these functions go towards one goal, and it is more appropriate way to use the globals between these functions. The class consists of three main sections, section one to add my meta boxes, section two […]

is_page not working when loading javascript with add_action in functions.php

This code is working in my functions.php and it’s loaded properly: add_action(‘wp_enqueue_scripts’, ‘js_custom’, 50); function js_custom() { wp_register_script( ‘js_custom’, get_template_directory_uri() . ‘/js/custom.js’, false, null); wp_enqueue_script( ‘js_custom’ ); } However, this is not working and not loaded: if ( is_page(273) ) { add_action(‘wp_enqueue_scripts’, ‘js_custom’, 50); function js_custom() { wp_register_script( ‘js_custom’, get_template_directory_uri() . ‘/js/custom.js’, false, null); wp_enqueue_script( […]

Is there a way to check which template file is being loaded, if it is not a page template file?

I don’t see any way of testing which template file is being loaded, if the template file is not a page template. Otherwise I would use is_page_template(). For instance, I am using a home.php template file to pull in the content from multiple pages(don’t ask), how would I check that home.php is the template file […]

Display sidebar if blog

I have two sidebars registered. One called Sidebar (sidebar-1) and the other called Blog Sidebar (sidebar-2). I would like to display the Blog sidebar on the blog index and single posts. As WordPress doesn’t have a conditional tag for the blog page, I have tried the following via sidebar.php: <?php if ( is_front_page() && is_home() […]

wp_head hook by page ID

I need help with this /* meta description to head */ add_action( ‘wp_head’,’carlos_head_meta_page’ ); function carlos_head_meta_page() { ?> <meta name=”description” content=”vale here” /> <?php } It works fine, but I would like to use a conditional tag like if ( is_page(‘4’) ) So I can use different meta tags for specific pages.

Same Conditionals Not Working on Two Different Hooks

Everyone! I am new to WP and trying to build a plugin. I have the following codes working properly: add_filter(‘the_content’, ‘say_hello’); function say_hello($content){ if(is_single() || is_page()){ print $content.” Thank you for reading!”; } else { print $content; } } But the following codes don’t seem to work: add_action(‘init’, ‘prepare_head’); function prepare_head(){ if(is_single() || is_page()){ // […]