![]() ![]() Many developers resort to including a third party library of their own, which then leads to big plugin or theme sizes and the potential for incompatibilities. So by registering them first, you would just need to register them once, and enqueue them in both related hooks. As pointed out earlier, there are two different hooks that need to be used in order to load your scripts and stylesheets on front end facing side and administrative side. Registering them first is also useful whenever you want to rely on the same script on a different part of the website. Based on several conditions, in this case, when the page loaded is of ID 32, or $var is set to true, we can dynamically enqueue them. ) īased on this snippet, you can see that we first register two custom scripts, my-custom-js and my-second-js. Make sure that the theme properly includes wp_head() and wp_footer() correctly for this to work. I even had a very strange issue, that the cached editor-style briefly appears (in a css-filtered) Firebug net panel for a split second, than disappears again. $in_footer is a Boolean flag that will tell WordPress whether to load your script in head section of document, or in the footer instead. 1) If you use firebug, xDisable Browser Cache in the Net panel helps. $ver is simply your script’s version, and it will be appended as a query string in your src parameter of script tag. By defining them here, WordPress will load those dependencies first before loading your custom scripts. $deps should be an array of scripts’ handle of which your script depends on. For a remote URL, protocol-agnostic URL such as ///ajax/libs/jquery/2.1.3/ can be used. You can get the proper URL using provided built in functions such as plugin_url(), get_template_directory_uri() and get_stylesheet_uri(). ![]() This is the most important part when enqueuing your script as the $handle will be the identifier of which script is to be loaded. $handle is the name of the script and should be unique. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |