You can call this function whatever you like. You need to make sure you are editing in-between the opening and closing PHP tags (). We will begin by creating a PHP function in our functions.php file. How to enqueue the main style.css stylesheetįirstly, let’s look at how to enqueue the main stylesheet of a WordPress theme: style.css. The most obvious possibility is that your theme is not using wphead () correctly, or at all. wpenqueuescripts is hooked to wphead, which fires in the wphead () function. using the wpenqueuescript and wpenqueuestyle functions, you inform WordPress when and where to load custom scripts and stylesheets. In this post, I’ll show you how to correctly enqueue stylesheets and script files in WordPress. I have to conclude that there is something wrong with the theme. I know this might sound complicated and it certainly confused me at first, but it will become second nature to you soon. So with our stylesheets and script files in WordPress, we are adding them to a queue and waiting for the correct moment to use them. If you aren’t familiar with the term “enqueue” it basically means to add data that is awaiting processing into a queue. The same applies to script files such as. The wpenqueuescript () function doesn’t support async/defer by itself, but luckily the scriptloadertag hook allows us to manipulate the wpenqueuescript () output really easily. However, in WordPress, the correct way to link to stylesheets is to enqueue them within the functions.php file of your theme. When you learn about CSS and external stylesheets you are taught to link to them using a link tag like this: Just put below code to theme’s functions.php file.For many years, the way I linked to external stylesheets in WordPress was incorrect. Using the Google CDN-hosted version of jQuery is another performance gain, because it will be cached for any visitors who have loaded another site that uses the same version. In below code snippets we have unregistered the default jQuery library from default WordPress, then added the Google CDN version after closing the footer tag. Here’s what the path should look like: child-theme-directory/js/follow.js Additional Speed Optimization Tips: ![]() This file includes the jQuery that will control the position of the sidebar follow section. In your Child Theme’s folder, create another folder called js, and then create a new file called follow.js and place that inside. ![]() ![]() '/js/follow.js', array( 'jquery' ), '', true ) Wp_enqueue_script( 'follow', get_stylesheet_directory_uri(). Enqueue sticky menu script - Crunchify TipsĪdd_action( 'wp_enqueue_scripts', 'crunchify_enqueue_script' ) Add below code to your child theme’s functions.php file. wpenqueuescript is used to enqueue script and wpenqueuestyle is used to. most of the jquery ui libs and core jquery files are already registered with wordpress so you only need to enqueue with right handle look here enqueue script. Here is a quick hook I’m using in my Genesis Framework theme for right sidebar sticky follow section. First thing jquery in there by default in wordpress so you dont have to register it, just enqueue it. ![]() It allows for greater control of when and where JS loads on your site. Using wp_enqueue_script is the best way to load JavaScript and jQuery into your WordPress template. The reason is pretty simple, HTTP/1.1 specification suggests that browsers not download more than two assets in parallel. Generally, it’s a good idea to include JavaScript / jQuery libraries and plugins at the bottom of the page, just before closing the body tag.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |