facebook

How to enqueue stylesheet and scripts in WordPress?

By Aheli Bharadwaj

How to enqueue stylesheet and scripts in WordPress?

 

Nowadays, WordPress is widely used for creating user interactive websites. WordPress is a free and open source CMS (Content Management System) based on PHP, MySQL. Though it is mainly used for blogging but also supports other types of websites including online stores, informative sites, mailing lists, and forums.

WordPress comes with its own default themes, but one can also install and switch other themes. With the help of themes, WordPress users can change the feel and look of the website, without changing the content. Another important feature of WordPress is plugins.

Users can add appropriate plugins to their sites by installing it from the dashboard. And after installation, it needs to be activated then only that particular plugin will be visible in the WordPress dashboard.

WordPress users can also create their own custom theme and give a creative look to their website. For that, the user may need to add the additional stylesheet and javascript files in the theme. So, here are the full details of enqueuing stylesheet and javascript.

The Method:

  1. To enqueue styles and JS libraries, go to functions.php file. 
  2. Enqueue the script using wp_enqueue_script() or enqueue the style using wp_enqueue_style()

Example :

To enqueue style in functions.php

wp_enqueue_style( ‘custom-css’, get_template_directory_uri() . ‘/css/custom.css’,false,’1.1′,’all’); 

To enqueue script in functions.php

wp_enqueue_script( ‘script’, get_template_directory_uri() . ‘/js/script.js’, array ( ‘jquery’ ), 1.1, true);

Web Designer , Openweb Solutions

Web Designer at Openweb Solutions

Posts created 4

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
shares