N
N
Nikita2015-12-10 15:44:14
WordPress
Nikita, 2015-12-10 15:44:14

Why isn't is_page working?

Good afternoon. You need to include styles only on the blog page, but the condition is not met. How to decide?

if( is_page(15944) ){
wp_enqueue_style( 'blog_style', get_stylesheet_directory_uri() . "/css/style_blog.css", false );
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex1nd, 2016-05-18
@alex1nd

is_page - for pages
is_single - for writing

////////////////
function my_styles() {
    if ( is_page( '933' ) ) {
        //подключаем стиль
        wp_enqueue_style ( 'contact', get_template_directory_uri() 
            . '/altercss.css', array(), '1.0' );  
            //подключаем скрипт
            wp_enqueue_script('alterscript', get_template_directory_uri() . '/alterscript.js');     
    }
}
add_action( 'wp_enqueue_scripts', 'my_styles' );
//////////////////

I checked everything works, you only need to change the ID and Paths to the files

E
Evgeniy, 2015-12-10
@eZhrv

As far as I can see, the problem can be in 2 places:
1. Page 15944 does not exist
2. Wp_enqueue_style is not used correctly ( Function Reference / wp enqueue style )
Most likely, you need to dig towards 2 points.
Detailed example: Load plugin styles only on its pages

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question