$in_footer: True ( places script before closing body tag).With all those parameters in mind, here is what a standard default enqueue of a Javascript file looks like: wp_enqueue_script( 'bxslider', get_template_directory_uri(). $in_footer - Set whether the script is loaded in the or just before the.$ver - The version number of the script (used for cache busting).$deps - An array of any other scripts needed as dependencies.$src - URL pointing to the directory of the script itself.$handle - the name associated with your script.The default script to enqueue an external JS file: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ) Important: Keep in mind that the wp_enqueue_style script will render the stylesheet link into the WordPress header automatically. In this example we have rendered the following: So, with all those parameters in mind, here is what a standard default enqueue of a CSS stylesheet looks like: wp_enqueue_style( 'google-fonts', '', '', '1.0', '') $media - Specify media type ( all, print, screen, etc.).$ver - The version number of the stylesheet (used for cache busting).$deps - An array of any other stylesheets needed as dependencies.$src - URL pointing to the directory of the stylesheet itself.$handle - the name associated with your stylesheet. The default script to enqueue a CSS stylesheet: wp_enqueue_style( $handle, $src, $deps, $ver, $media ) I suggest you read the official documentation for more details: wp_enqueue_script and wp_enqueue_style. Best practice being: styles into the header, scripts into the footer. In a nutshell: Placing a wp_enqueue_script or wp_enqueue_style script in the functions.php of your custom theme tells WordPress to pull external files into the header or footer of your website. Registers the style if source provided (does NOT overwrite) and enqueues The description of Wp Enqueue from the WordPress documentation: (Which is awesome!) Introducing WP Enqueue This post is purposefully catered for WordPress beginners, so if this seems overly simple, then you're probably already developing WordPress themes that utilize these techniques. This is perfectly fine, but there is a cleaner way to include these files. Throughout my career designing, developing and auditing WordPress themes, I've come across many that include their custom styles / scripts as static HTML elements inside their respective header and footer templates. WP Enqueue for Beginners Menu ↓ WP Enqueue for Beginners
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |