pefoki.blogg.se

Wordpress enqueue script on specific page
Wordpress enqueue script on specific page




wordpress enqueue script on specific page
  1. WORDPRESS ENQUEUE SCRIPT ON SPECIFIC PAGE HOW TO
  2. WORDPRESS ENQUEUE SCRIPT ON SPECIFIC PAGE FULL

How to load CSS and JS to a specific page template?

wordpress enqueue script on specific page

'/your-script-path/script.js', array ( 'jquery' ), 1.1, true) Your enqueue function would be like: wp_enqueue_script( 'custom-script', get_template_directory_uri().

  • $in_footer Whether to enqueue the script before instead of in the.
  • This script will not be loaded unless its dependent script is loaded first.
  • $deps refers to an array of registered script handles.
  • WORDPRESS ENQUEUE SCRIPT ON SPECIFIC PAGE FULL

    $src is the full URL of the script or path of the script relative to the WordPress root directory.$handle is simply a unique name of the script.wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer) Note: get_template_directory_uri() signifies your theme’s root directory.

    wordpress enqueue script on specific page

    '/your-stylesheet-path/stylesheet.css', false, '1.1', 'all' ) So if you wanted to enqueue your style, you would use: wp_enqueue_style( 'custom-stylesheet', get_template_directory_uri(). Accepts media types like ‘all’, ‘print’ and ‘screen’, or media queries like ‘(orientation: portrait)’ and ‘(max-width: 640px)’.

  • $media can specify for which this stylesheet has been defined.
  • If the version is set to false, a version number is automatically added equal to the current installed WordPress version.
  • $ver sets stylesheet version number if it has one, which is added to the URL as a query string for cache busting purposes.
  • This stylesheet will not be loaded unless its dependent stylesheet is loaded first.
  • $deps refers to an array of registered stylesheet handles.
  • $src is the full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
  • $handle is simply a unique name of the stylesheet.
  • In this function we need to enqueue our style, the basic function to do so is: wp_enqueue_style( $handle, $src, $deps, $ver, $media ) Below the comment, you will be able to see a function theme_name_scripts (Figure-1). There you will be able to find functions.php, open it in your text editor, and search for the comment Enqueue scripts and styles.
  • How to load CSS and JS to a specific page template?įirst of all, we need to go to our active WordPress theme directory ( KP-site\wp-content\themes\kode-pundit ).įor the sake of this tutorial, we renamed the WordPress folder to KP-site and generated a starter underscores theme and kept the theme name as kode-pundit.
  • Why does performance matter? Because it can be used to get leads, rank higher in search engines, retain visitors, and many more thus making the website meet its objectives. Creating and adding CSS and JS to a specific page not only allows you to easily maintain your website but also increases its performance of it by not being loaded on irrelevant pages.






    Wordpress enqueue script on specific page