The main benefits for using wpenqueuescript () are: You can set dependencies for the scripts you load, so for example you could add jquery as a dependency for your main. You can call this function whatever you like. wpenqueuescript () works as an additional layer for these wphead and wpfooter filters. You need to make sure you are editing in-between the opening and closing PHP tags (). I am working on a plugin that has to inject a script on pages (something like RefTagger), which would be easy using wpenqueuescript, but there are two reasons I cannot do that: the script tag has to have an ID and it should be executed asynchronously. 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. In this post, I’ll show you how to correctly enqueue stylesheets and script files in WordPress. 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. Though it can probably be simplified somewhat. However, in WordPress, the correct way to link to stylesheets is to enqueue them within the functions.php file of your theme. Use enqueue as normal, use script for CSS files with a false tag at the end so that it loads at the top. When you learn about CSS and external stylesheets you are taught to link to them using a link tag like this: For other WordPress functions, please contact us if you need help.For many years, the way I linked to external stylesheets in WordPress was incorrect. We are highly experienced in WordPress and web development and are equipped in solving any issues you might be facing.ĭo note that this guide is purely for enqueuing external scripts on WordPress. Unsure of where to insert this? Don’t want to break anything? Our team of WordPress developers in Singapore can accomplish this job for you safely and efficiently. Within the action hook, you can use several functions and embed them in the functions. Let’s go through the basics of the wpenqueuescript hook that you’ll use to load your assets. You can also set dependencies if you wish - for more information, please visit the official WordPress documentation. Add Enqueue Script or Style actions to a
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |