0

I created a page template named custpage.php I also created a separate css file named style2.css to style the custpage which has html and php code. The page templates loads fine it shows under the page attributes but the css stylesheet doesn't seem to work.

This is what I did in functions.php

function register_cust_style() {
  if ( is_page_template( 'custpage.php' ) ) {
    wp_enqueue_style( 'vega', get_stylesheet_directory_uri() . '/style2.css' );
  }
}
add_action( 'wp_enqueue_scripts', 'register_cust_style' );

The css file is inside vega/style2.css (where vega is name of the template directory).

1

This will work only if your template is in the root folder, if its in a subdirectory you need to supply that too:

if ( is_page_template( 'template_folder_name/custpage.php' ) ) {
    wp_enqueue_style( 'vega', get_stylesheet_directory_uri() . '/style2.css' );
}
0

'vega' - must be unique name (example: 'vega-custpage-css')

wp_enqueue_style( 'vega-custpage-css', get_stylesheet_directory_uri() . '/style2.css' );

Style file must be located:

http://site.ru/wp-content/themes/twentyten/style2.css
0

To help debugging, you really want to know first off if is_page_template is returning true or not... for that you can do something like...

add_action('wp','page_template_check');

function page_template_check() {
    if ( is_page_template( 'custpage.php' ) ) {
        echo "<!-- custpage.php is correct -->";
    }

    $template = get_page_template_slug( get_the_ID() );
    echo "<!-- Template: '".$template."' -->";
}

(the second test is from the is_page_template developer codex page.

Then view the page source... if they are different results then adjust, if they are the same then the problem is with the enqueueing after all (you need a unique slug as @TrubinE mentioned.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.