1

To include custom css and javascript within a blog post or a page, one option would be to embed a jsbin, codepen, or plunkr link. In cases where you wanted to include external libraries like angular.js, d3.js, etc., these code editors and environments would provide a nice sandbox (both from a css and a js perspective) to embed in a Post or a Page.

Are there better options available and native to wordpress for creating custom pages where you have complete control over what css and js files get included in a Page?

1

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.

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.