I built a custom WordPress site for some artists. I'm making one page that is entirely different from the rest of the site. Actually, that and a single.php page. It's for a specific new book, and the only reason it's on the same install is that it shares the blog posts. The rest is all specific.

These pages don't need any css or js from the rest of the site - in fact, that is getting in my way. I'm having to overqualified everything and I worry that spill over is going to break the main site.

They have their own header-books.php and footer-books.php

How can I get them to have their own functions.php so that I can pull in css and js that is totally separate from the main site?

(ps - it's way too late for multi site or any big ideas)

Thank you.

  • DW
  • Just give that specific page a body_class and then load your css and js conditionally for that page Apr 9, 2014 at 22:32
  • That's what I'm doing so far. Apr 9, 2014 at 22:59

2 Answers 2


functions.php unfortunately is very ingrained part of theme load process. If your architecture is flexible enough you should be able to conditionally unhook related bits.

Even if it's not — templates give you complete control over page output. You could go as far as completely omitting wp_head()/wp_footer() calls and handle assets (semi-)manually if that is shortest way to address requirements.

  • soo I can just do an if not these two pages, and an if these to pages... in the functions when I call scripts then maybe... ? Apr 9, 2014 at 23:03
  • Either way - this is the answer... You basically just can't have two functions.php's - which is what I wanted to know. Thanks! Apr 9, 2014 at 23:04

This can easily be done with body classes and conditional statements. Looking at your question, you will have a custom 'page.php' and 'single.php' for what you are doing. For this purpose, I'll call them 'page-custom.php' and 'single-custom.php'

We can now assign a body class to these pages with the following function

function mytheme_body_classes( $classes ) {
    if ( is_page_template( 'page-pop.php' ) || is_page_template( 'single-custom.php' ) ) {
        $classes[] = 'special';
    return $classes;

add_filter( 'body_class', 'mytheme_body_classes' );

This will assign a class of special to these pages.

You can now create a stylesheet inside the css folder and call it 'custom.css'. Also create a js file in the js folder and call it 'custom.js'

You can load your stylesheet and js files conditionally so that they only load on these two specified pages with the body class special

function myscripts_enqueue() {
    $classes = get_body_class();
        if (in_array('special',$classes)){
            wp_enqueue_style( 'custom-css', get_template_directory_uri() . '/css/custom.css', array() );
            wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), '' , true );
add_action( 'wp_enqueue_scripts', 'myscripts_enqueue' );
  • 1
    A little unorthodox use of body class as conditional, would work just fine though. :)
    – Rarst
    Apr 10, 2014 at 9:52

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .