Dequeue & Enqueue Scripts

Dequeuing Scripts & Stylesheets

To remove the stylesheets and scripts that you don't need from the theme source code:

  • Create a child theme if it doesn't exist yet (creating a child theme will prevent theme updates overwrite your work)
  • In the child theme functions.php, add the dequeue/enqueue functions as referenced below
  • to dequeue a stylesheet, use wp_dequeue_style plus the handler name in the quote
  • to dequeue a Javascript, use wp_dequeue_script plus the handler name in the quote
  • the example below will remove: google-fonts and media-queries.css
[code type=php]<?php

add_action( 'wp_enqueue_scripts', 'themify_remove_scripts', 20 );

function themify_remove_scripts(){
wp_dequeue_style( 'google-fonts' );
wp_dequeue_style( 'themify-media-queries' );
}

?>[/code]

Enqueuing Scripts & Stylesheets

To add more stylesheets and scripts, use the wp_enqueue_style and wp_enqueue_script (again, this can be added in custom-functions.php):

  • to enqueue a stylesheet, use wp_enqueue_style plus the handler name and file location (get_template_directory_uri in the sample code below will output the theme folder path)
  • to enqueue a Javascript, use wp_enqueue_script plus the handler name and file location
  • the example below will add script.js and custom.css from the theme folder
[code type=php]<?php

add_action('wp_enqueue_scripts', 'themify_add_scripts');

function themify_add_scripts(){
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/script.js');
wp_enqueue_style( 'style-name', get_template_directory_uri() . '/custom.css');
}

?>[/code]