![]() ![]() The function requires a unique id that was used to register a style. add_data Function usage.Īdd_data method adds the custom attribute to a specific stylesheet link tag. WordPress developer page has a deep explanation on WP_Styles, it is good to check it. Since add_data can be used to register a new stylesheet. Without passing three arguments, the link tag can output something else. To include custom attributes, a function should receive three string parameters. The shortcode in the example above uses the add_data method to register the attribute in the stylesheets. WP_Styles extends WP_Dependencies, the class that offers twelve methods. $wp_styles is an instance for the wordpress class that enqueue and order a stylesheet attributes. Let me explain briefly the work of each object and function from the given example. Write this shortcode in the functions.php file. $wp_styles->add_data(“customAttribute”, “media”, “print”) Īdd_action(‘wp_enqueue_styles’, ‘custom_attribute’) This explanation can be summarized in the following WordPress code. ![]() The first parameter defines a handle, the second parameter is an attribute and the last parameter is a value of a provided attribute. $wp_styles should call add_data function, which receives three parameters. However, there is a way to use wp_enqueue_styles to add attributes to a stylesheet.Īttribute can be added to wp_enqueue_styles using global WordPress variable $wp_styles. That objective may not be achieved if the stylesheet was added by wp_enqueue_styles. The properties of link tags can be used to serve a specific task like specifying a media type for setting out how to render a page on various devices. Wp_enqueue_styles registers only a stylesheet without including extra attributes and its parameters don’t pass link attributes. Do you find it difficult to add custom attributes like the title to a link tag using wp_enqueue_styles in WordPress? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |