Posts

Showing posts with the label wp_enqueue_script

Enqueue Stylesheet or Javascript on just one Wordpress Page or Post

To enqueue a css stylesheet or external javascript file on just one page use the following function with a conditional if statement in your child theme functions.php script. function register_online_form_style() {   if ( is_page( '104' ) ) {     wp_enqueue_style( 'contactForm', get_stylesheet_directory_uri() . '/site/css/form.min.css' );   } } add_action( 'wp_enqueue_scripts', 'register_online_form_style' ); 104 is the page or post's ID contactForm is the name of the script Pretty starightforward

How to add links to Javascript files in Wordpress Child Theme using wp_enqueue_script

Took some to figure this out. In your "functions.php" file in your child theme directory add this code function wpb_adding_scripts() { if (!is_admin()) { wp_register_script('my_amazing_script', get_stylesheet_directory_uri() . '/js/scroller.js', array('jquery'),'1.1', true); wp_enqueue_script('my_amazing_script'); } } add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' ); This function checks that you are not logged in as an administrator. my_amazing_script can be named anything you like get_stylesheet_directory_uri() is important if you're doing this in your child theme functions.php file 1.1 is your version number and can be anything true is to load the JS file at the bottom of the page, false is to load the JS file at the top of the page