A safe way to add/enqueue a CSS style file to the wordpress generated page. If it was first registered with wp_register_style() it can now be added using its handle.

learn more… | top users | synonyms

27
votes
1answer
6k views

Where is the right place to register/enqueue scripts & styles

I am using WordPress 3.1.4 by now. I am confused with where (which hook) do I use: to register and/or enqueue scripts and styles on front- and back-ends? Questions: Which are right hooks to ...
23
votes
7answers
9k views

Conditionally Loading JavaScript/CSS for Shortcodes

I released a plugin that creates a shortcode and requires a JavaScript file and a CSS file to load on any page that contains that shortcode. I could just make the script/style load on all pages, but ...
18
votes
5answers
9k views

How do I enqueue styles/scripts on certain /wp-admin pages?

I have two simple functions that load stuff using wp_enqueue_style() and wp_enqueue_script(), something like these: function admin_custom_css() { wp_enqueue_style( 'stylesheet_name', ...
18
votes
2answers
5k views

Check if a script/style was enqueued/registered

Is it possible to test whether a script or a style was registered using wp_register_script/_style or wp_enqueue_script/_style? All functions doesn't return a value and I'm completely clueless. I ...
17
votes
2answers
559 views

Is it ever okay to include inline CSS in plugins?

Normally in a plugin I would add styles using wp_enqueue_style. However, I am currently creating a plugin that only needs a few lines of CSS and I am wondering if it might be better to serve the ...
13
votes
3answers
2k views

How important is it to enqueue a theme's stylesheet?

I have trawled the net looking for an answer to this, but for some reason all I can find are actual examples, but without that particular explanation, which is clear say in the case of scripts. Can ...
11
votes
1answer
6k views

How do I dequeue a parent theme's CSS file?

My parent theme (Starkers) adds a CSS file that I'm trying to remove (I want to use @import instead so I can override styles more easily). Starkers has the following in its functions.php: add_action( ...
8
votes
4answers
5k views

Remove Open Sans from Twenty Twelve theme

I´m creating a child theme for Twenty Twelve v1.0 and I want to remove the Open Sans font. Open Sans is added in Twenty Twelve´s functions.php: wp_enqueue_style( 'twentytwelve-fonts', ...
7
votes
4answers
2k views

LESS CSS enqueue_style with add_filter to change rel attribute

What I'm trying to do is use less css with Wordpress. You're supposed to link to your .less files with the rel attribute set to 'stylesheet/less'. But I can't figure out how to alter the code that ...
6
votes
1answer
5k views

Why is style.css not being enqueued?

I got a pretty basic theme and just found out my style.css file doesn't get loaded into the <head>. I already searched around but can't find out, why it's not loading. I inspected the global ...
6
votes
1answer
5k views

How to load Widget javascript + css files only if used?

I'd like to keep the javascript and css styles used by my widget inside their own files (and not add them to the theme). But i can't seem to get wordpress to add them when the widget is actually used ...
5
votes
4answers
3k views

Enqueue Google Web Fonts Without Messing Up Symbols In URL

Enqueuing Google Web Fonts the usual way, i.e., using the wp_enqueue_style function like so... function wpse_google_webfonts() { wp_enqueue_style( 'google-webfonts', ...
5
votes
1answer
2k views

Enqueue a stylesheet for login page and make it appear in head element

I try to style the login page in my theme. Very simple: add_action( 'login_enqueue_scripts', function() { wp_enqueue_style( 'TEST', get_template_directory_uri() . '/css/login.css' ); }); ...
5
votes
1answer
2k views

Load js/css files only on specific admin UI pages

How do I adapt this solution to work with my plugin? (Please see the link). I enqueue my css and js script as follows: function my_plugin_init() { wp_enqueue_script('my_plugin_script', ...
5
votes
1answer
4k views

How to enqueue style before style.css

How do I enqueue a .css file before style.css is loaded? Or make the default style.css dependant on another .css file? I'm trying to load a .css reset, which style.css would overwrite. Here's what I ...
4
votes
2answers
1k views

How Would You Enqueue A Google Web Font?

I'm using the Rosario font from the Google Web Fonts in my theme and I want to enqueue the font so that if there was ever a plugin that used a fancy font that there wouldn't be any conflicts or wasted ...
4
votes
2answers
406 views

Why I can't add a CSS style in this WordPress theme?

I am trying to add a CSS style to a WordPress theme that I am developing as is shown in this tutorial: http://www.wpbeginner.com/wp-tutorials/how-to-properly-add-javascripts-and-styles-in-wordpress/ ...
4
votes
3answers
1k views

How to add stylesheets only to pages with specific shortcode?

I'm running a function on pages where the shortcode [make-me-a-map] is used. It enqueues javascript to the page and makes a map. That part works fine (woot!) but I'm having trouble with adding the ...
4
votes
1answer
167 views

Duplicated CSS files using wp_enqueue_style()

I've noticed that in the source code of my website there is Font Awesome loaded five times. Loaded versions are 3.2.1, 4.0.1, 4.1.0 and more. Shortcodes plugins, page builders, the theme and/or ...
4
votes
1answer
1k views

Issues enqueueing parent & child theme stylesheets with revised Codex method

This post brings up a few questions I've encountered pertaining to the recent changes around stylesheet enqueueing methods brought up in this thread and this thread. The issues I encountered came up ...
3
votes
2answers
2k views

How can I de-register ALL styles all at once? And same with Javascript?

How can I get all enqueued styles or scripts and then deregister them all at once?
3
votes
2answers
6k views

Notice that the wp_enqueue_style is not being called correctly!

I get this error due to one of the plugins which I rely on. Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, ...
3
votes
1answer
2k views

Why wp_register_style() is important while I'm using a complete wp_enqueue_style()? [duplicate]

Currently I'm working on a theme, and did some styles and scripts enqueue. When enqueued the scripts, I used wp_register_script() first, and then enqueued with wp_enqueue_script() - because I got ...
3
votes
1answer
3k views

Inbuilt style for jquery-ui-datepicker

I want to use the datepicker that gets bundled with WordPress on the front end of a website. I enqueued jquery-ui-datepicker but the datepicker isn't styled(no js error in console). Is there a ...
3
votes
1answer
123 views

Hyphens vs. periods in the script slug in wp_register_script?

I have seen script and style handles written in two different ways in wp_register_script and wp_enqueue_script (the same applies to wp_register_style and wp_enqueue_style): wp_register_script( ...
3
votes
2answers
39 views

Why shouldn't @import be used to import a parent theme into a child theme?

I have some experience with Wordpress but I've been away from it for awhile. I've seen many examples of using @import in the beginning of the child theme to import the parent theme. I was surprised ...
3
votes
2answers
109 views

Get list of scripts / styles and show file which enqueued them

I want to show what scripts and styles have loaded on a page and which plugin / theme / file has added them to the page. We can show all scripts and styles using: <?php global $wp_scripts, ...
3
votes
1answer
237 views

TinyMCE custom stylesheets for different post types

I use a custom stylesheet for TinyMCE, by placing custom styles in editor-style.css in my theme's directory. I am trying to figure out how to use a different stylesheet depending on what post type we ...
3
votes
1answer
642 views

How to combine multiple CSS files and concatenate JavaScripts if WordPress recommends enqueuing them?

How would I go about combining multiple CSS files and concatenating my scripts if they're being enqueued as WordPress recommends? My site is pretty slow and would like to optimize for performance.
2
votes
2answers
5k views

wp enqueue style on specific page templates

I am in the process of a theme, I would like to add landing pages using page-templates. I cannot find anywhere that shows how to enqueue style or js for specific page templates. Any suggestions. Ex. ...
2
votes
2answers
2k views

Wordpress admin stylesheet

Is there a way to override the styles in the admin in my theme? I don't want to touch the admin style sheet if I don't have to. I just want to make a column bigger in my admin, but also, to do it in ...
2
votes
2answers
1k views

When enqueing a stylesheet, is it possible to remove the type attribute?

I'm updating my self-built theme to HTML5, and easily made a number of changes already. My theme's sole stylesheet is added to the page head via wp_enqueue_style in the functions.php file, as ...
2
votes
3answers
307 views

Is it possible to enqueue a raw CSS string directly from within a template file?

I was wondering if it's possible to enqueue raw CSS as a string directly from within a template file? I'm writing a custom template for a page and need to add some style rules for it. What I want to ...
2
votes
1answer
53 views

Stylesheet from wp_enqueue_style is overwritten by plugin

I am using Font Awesome on my theme. wp_enqueue_style('fontawesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css'); I am using another plugin that uses Font Awesome, but ...
2
votes
1answer
69 views

How to control the order of the combination of enqueued styles and scripts - site speed issue

We know, using wp_head() and wp_footer() all the scripts and styles are enqueued using wp_enqueue_styles and wp_enqueue_scripts hook. What we do is to enqueue our stylesheets and scripts using ...
2
votes
3answers
143 views

How to detect if a function has been fired on any page so scripts/styles can be loaded conditionally

I'm building a small gallery plugin and I'd like to only load scripts/styles onto the page IF the gallery has been loaded via the template tag. The template tag can take a post ID parameter when used ...
2
votes
1answer
177 views

Dynamically Load Styles and Scripts from Theme Functions.php

I am attempting to dynamically load stylesheets and scripts based on the template name. So if I have a template named page-signup.php then it will load the corresponding stylesheet page-signup.css and ...
2
votes
1answer
30 views

Is it possible to change the path of a css file that is registered through wp_enqueue_style()?

The theme I am using already calls the wp_enqueue_style function to enqueue a css file. I want to whether it is possible to change the css file path before it is actually outputted on the page. Why ...
2
votes
2answers
3k views

How to override enqueued styles using a child theme

I'm creating a child theme (My first in over 3 years) of a WooCommerce theme and I'm having some trouble with the fact that some of the layout styles are enqueued in the parent theme and I'm having to ...
2
votes
1answer
1k views

How to use wp_enqueue_style() and wp_enqueue_script() only when needed?

My plugin uses wp_enqueue_style() and wp_enqueue_script() to load resources, but I have kept in mind not to degrade the performance for the user and only load these when the current set of posts ...
2
votes
2answers
3k views

How to conditionally enqueue a stylesheet only for a certain page(s)?

Before I get started, I want to acknowledge that there are some really good articles that are targeted at how to conditionally enqueue scripts based on page/post content. WordPress Plugin ...
1
vote
2answers
2k views

How to add dynamic inline style?

I want to add dynamic CSS, so currently I am adding directly to the div, ie: $color = "#000000"; echo '<div style="background:'.$color.'"> Is it bad to add code like above? I have read in ...
1
vote
2answers
88 views

Why are my styles being applied to the admin area?

All my enqueued styles are applied to the back-end as well. I have never encountered this behavior before. Here's my code: wp_register_style( 'main-styles', get_stylesheet_directory_uri() . ...
1
vote
3answers
4k views

Style custom columns in admin panels (especially to adjust column cell widths)

I am using Wordpress as a CMS for a project which makes extensive use of custom post types. I need to display columns in admin panels for each custom post type in a different way. I've already ...
1
vote
3answers
227 views

The best way to add stylesheets to WordPress

I am in the process of converting a mobile responsive page, currently built in Bootstrap into WordPress. Using wp_register_style() and wp_enqueue_style() will add the stylesheets to all pages, ...
1
vote
2answers
8k views

How to enqueue the style using wp_enqueue_style()

I'm developing a theme. I added the codes (below) into the header.php. But I posted it into the WP theme repository, and it's under review, and the reviewer informed me to enqueue the style with ...
1
vote
2answers
97 views

CSS file not registering through add_action

Im having a problem to register and load a gallery css code from my home page. Rest of the styles are loading fine, but this flexslider is not registering. Any guidance appreciated. <?php ...
1
vote
3answers
183 views

To enqueue or not to enqueue

What is the best way to link to a CSS file in WordPress? Method 1: Use the following whenever needed <link href="<?php echo get_template_directory_uri(); ?>/my-style.css" rel="stylesheet" ...
1
vote
2answers
263 views

getting url in wp_enqueue_style

I'm having trouble getting the second argument in wp_enque_style. Here's how my site is setup: style.css custom_style.css index.php In a template, I have this code: $stylesheet_url = ...
1
vote
1answer
834 views

Load custom css after bootstrap

I have this in functions.php. How can I modify it so that my custom css is loaded after bootsrap.min.css? function register_css() { wp_register_style( 'bootstrap.min', ...