What are the options for running custom css and javascript files on a page?

You can use WordPress built in functionality Function Reference/is page and attach a if statement in your script_enqueue() function in your functions.php file.

Read more in the Codex:

https://codex.wordpress.org/Function_Reference/is_page

Here’s an example from a theme I’m building:

if (is_page( array('mortgage-calculator', 'contact' ) )){
            wp_enqueue_script('angularjs', get_template_directory_uri().'/js/angular.min.js', array(), '1.4.1', true);
            wp_enqueue_script('d3', get_template_directory_uri().'/js/d3.min.js', array(), '10/22/2015', true);
            wp_enqueue_script('c3-js', get_template_directory_uri().'/js/c3.min.js', array(), '10/22/2015', true);
            wp_enqueue_script('c3-css', get_template_directory_uri().'/css/c3.min.css', array(), '10/22/2015', false);
            wp_enqueue_script('fcsaNumber', get_template_directory_uri().'/js/fcsaNumber.min.js', array(), '1.0.0', true);
            wp_enqueue_script('mortCalcApp', get_template_directory_uri().'/js/mortCalcApp.js', array(), '1.0.0', true);
    }

These files will only be used on these two pages.

Leave a Comment