If you were enqueuing a stylesheet located at /assets/css/example.css in your theme, your function call might look like this: wp_enqueue_style( $media is for specifying which type of media to load this stylesheet for, such as all (default), screen, print, or handheld.Defaults to the current WordPress version. $ver sets the version number of your stylesheet and is used for cache busting.$deps is an optional array of other stylesheet handles that your stylesheet is dependent upon.While it is technically an optional parameter, it is required to actually load a specific stylesheet. $src is the file URL of your stylesheet.$handle is a unique name/ID for the stylesheet and should be prefixed with your theme slug. Take a look at the function signature: wp_enqueue_style( You’ll learn which action hooks to use for specific scenarios in the next sections. You would use this function within an action hook callback in your functions.php file, which you learned about in Custom Functionality. Wp_enqueue_style() is the primary function for enqueueing a stylesheet, which tells WordPress that you want to put it in the queue to load. get_parent_theme_file_path( $file ): Returns the parent theme’s directory path, with an optional $file parameter.Falls back to the parent theme if a child theme is active and the file doesn’t exist. get_theme_file_path( $file ): Returns the active theme’s directory path, with an optional $file parameter.get_parent_theme_file_uri( $file ): Returns the parent theme’s URL, with an optional $file path.įor directory paths, which are needed less often for assets, there are two primary functions:.get_theme_file_uri( $file ): Returns the active theme’s URL, with an optional $file parameter.get_stylesheet_uri(): Returns the active theme’s style.css file URL.Three of the primary URL helper functions are: You should always use these helper functions when including any type of asset to ensure the URL or path is correct. URL and directory path functionsīefore including assets, you should become familiar with some of the utility functions that WordPress provides for getting URLs and directory paths within a theme. This is necessary for loading CSS stylesheet and JavaScript files. You must also understand how to use your theme’s functions.php file. You will need some baseline PHP and HTML knowledge to follow along. This documentation is a leap forward in comparison to some of the previous pages in the Core Concepts chapter. In this document, you will learn the necessary functions for generating the proper URL to point to asset files and how to include scripts, styles, and other assets in your theme. This ensures that WordPress, any active plugins, and your theme all play nicely together. WordPress has specific hooks for determining when to load scripts/styles and functions for generating the markup. But you should never manually hard code these HTML elements in your theme. The same might be true for including JavaScript via the tag. If you are familiar with HTML, you might be accustomed to including CSS stylesheets via the or tags. But there are times when you might need to include a CSS stylesheet, custom JavaScript file, or even other types of media. For design aspects, specifically, much of this can be handled through the Global Settings and Styles system. Many block themes do not need to load any assets.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |