Is it possible to change the attributes of a registered style or script before it fires?

Modify a registered style’s path I wanted to tweak the path to one of the WordPress admin stylesheets so i could keep requests down, and because it makes little sense to include two stylesheets, when the one i’m calling redefines all the styling in the stylesheet enqueued by WordPress. The idea is basically to re-point … Read more

Modernizr and WordPress – How can I add a CSS class to the html element?

This is not exactly the answer, but you can use a hook for language_attributes filter. This action is fired at <html> tag and what it does is simply echo the lang=en string, for ex. You can hook to that and replace the string with your CSS class, like this: add_filter(‘language_attributes’, ‘modernizr’); function modernizr($output) { return … Read more

How to add extra attribute to stylesheet link?

We can use style_loader_tag filter to filter the link that is being output. Here is the filter: $tag = apply_filters( ‘style_loader_tag’, “<link rel=”$rel” id=’$handle-css’ $title href=”https://wordpress.stackexchange.com/questions/231597/$href” type=”text/css” media=”$media” />\n”, $handle, $href, $media); Here the link $handle for which you want to add attribute is font-awesome so if the handle, so you can replace font-awesome-css with … Read more

Give priority to child theme stylesheet

Your child theme’s stylesheet will usually be loaded automatically. If it is not, you will need to enqueue it as well. Setting ‘parent-style’ as a dependency will ensure that the child theme stylesheet loads after it. /** * Enqueue theme styles (parent first, child second) * */ function wpse218610_theme_styles() { $parent_style=”parent-style”; wp_enqueue_style( $parent_style, get_template_directory_uri() . … Read more

How to remove CSS file in the header using WordPress functions?

If your stylesheet is registered and enqueued correctly then… function dequeue_my_css() { wp_dequeue_style(‘my-css’); wp_deregister_style(‘my-css’); } add_action(‘wp_enqueue_scripts’,’dequeue_my_css’); // add a priority if you need it // add_action(‘wp_enqueue_scripts’,’dequeue_my_css’,100); … should remove it. That only works if the stylesheet was registered and/or enqueued with wp_register_style and wp_enqueue_style. If it is not registered correctly then you will have to … Read more

How to add a class to ul tags created by the WordPress editor Tinymce?

It’s always a good idea to look at WordPress Codex before asking. TinyMCE Custom Styles <?php // Insert ‘styleselect’ into the $buttons array function my_mce_buttons_2( $buttons ) { array_unshift( $buttons, ‘styleselect’ ); return $buttons; } // Use ‘mce_buttons’ for button row #1, mce_buttons_3′ for button row #3 add_filter(‘mce_buttons_2’, ‘my_mce_buttons_2’); function my_mce_before_init_insert_formats( $init_array ) { $style_formats … Read more

localize inline css

You could use the wp_head hook and inject your <style> tag directly into the <head>. Note: make sure you’re firing the wp_head() function in your template (which you should be doing already). add_action(‘wp_head’, ‘random_background_image_wpse_83275’); function random_background_image_wpse_83275() { $images = array( ‘/path/to/image1.jpg’, ‘/path/to/image2.jpg’, ‘/path/to/image3.jpg’, ‘/path/to/image4.jpg’, ); $image = $images[rand(0, count($images)-1)]; echo ‘ <style> html { background: … Read more