Tag Info

Hot answers tagged

22

WordPress knows what it is doing here. Honest. When rendering an ampersand in HTML, you should always use & or &. The browser then converts it to & before actually firing the HTTP request. See for yourself by inspecting the network calls in a web inspector tool. You're not actually losing your non-latin subsets. Notice the ...


16

It's important to enqueue the stylesheet because it will allow child themes the flexibility of dequeueing it as well as allowing it to be listed for dependencies and a multitude of other things. It just generally allows greater flexibility, both for you and for any other developers who interact with your code. It's also important to note that using the ...


15

As an addition to the other answer by @m0r7if3r: You can use current_theme_supports() to only load the parent themes stylesheet if there's theme support. function add_supported_stylesheets() { if ( current_theme_supports( 'parent-stylesheet' ) ) wp_enqueue_style( 'main', get_stylesheet_directory_uri().'/style.css', array(), filemtime( ...


13

This may be inappropriate, please let me know if I missed something. The fourth argument to wp_enqueue_style() is the stylesheet's version number. In your theme's functions.php: function my_theme_styles() { // replace "10" with your version number; increment as you push changes wp_enqueue_style('my-theme-style', get_bloginfo('template_directory') . ...


13

Hi @Ash G: I didn't follow 100% where you were specifically having problems so I'm not sure I really can answer your issues point-by-point but I can explain how to do this from ground up. And unless what you are doing is a good bit more involved then you mentioned it's a little bit more work than I think you were anticipating but it is still completely ...


10

I would say: you should not use the style.css for the actual production CSS. The reason is simple: minification. You cannot minify the content of the file completely, because WordPress has to read it. In my themes, I use style.css just for the headers, and I add a comment, explaining where to find the real CSS, so other developers don’t have to search too ...


8

Enqueue the style.css too, and set normalize as dependency: function load_css_files() { wp_register_style( 'normalize', get_template_directory_uri() . '/css/normalize.css'); wp_register_style( 'theme_name', get_stylesheet_uri(), array( 'normalize' )); wp_enqueue_style( 'theme_name' ); } WordPress will load the dependencies now first ...


7

Just FYI, this question probably borders on too localized, as it is specific to the Oenology Theme. That said, here's where I think you're having a problem: Oenology enqueues two style sheets: style.css, directly in the document head (thus before wp_head() is fired) {varietal}.css, at wp_enqueue_scripts, with priority 11, in functions/dynamic-css.php: ...


7

Stylesheet Printing Order WordPress does not load themes' alternative rtl.css files using wp_register_style() or wp_enqueue_style(). As such, the stylesheet does not get added to WordPress's style queue, and cannot be specified as a dependency when registering or enqueueing additional stylesheets. Instead, this stylesheet's <link> element is added ...


7

You don't have to use @import. It's best not to, actually. Using an enqueued approach is probably better all around. Here's the relevant part of twentythirteen's code: function twentythirteen_scripts_styles() { ... // Loads our main stylesheet. wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '2013-07-18' ); ... } ...


5

According to WordPress Codex (here): admin_enqueue_scripts is the first action hooked into the admin scripts actions. Example Loading a CSS or JS files for all admin area: <?php //from functions.php //First solution : one file add_action( 'admin_enqueue_scripts', 'load_admin_style' ); function load_admin_style() { ...


5

Use wp_enqueue_style to add a print stylesheet, note the media parameter that lets you make it a print-specific stylesheet: function wpa_print_styles(){ wp_enqueue_style( 'wpa-print-style', get_stylesheet_directory_uri() . '/print-style.css', array(), '20130821', 'print' // print styles only ); } ...


5

Try this (will also handle HTTP vs HTTPS): function wpse_google_webfonts() { $protocol = is_ssl() ? 'https' : 'http'; $query_args = array( 'family' => 'Ubuntu+Condensed|Open+Sans:400italic,700italic,400,700', 'subset' => 'latin,latin-ext', ); wp_enqueue_style('google-webfonts', add_query_arg($query_args, ...


5

That would be because get_stylesheet_directory_uri only returns a value. If you want to echo it to to the screen you have to include echo or print. <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.jpg" /> bloginfo works fine as well, but when you do stylesheet_directory it's just a wrapper for get_stylesheet_directory_uri ...


5

I'm a little confused by your question, can you not simply use wp_enqueue_style, which you actually wrote into this threads heading(not sure if you know the function exists or not). wp_enqueue_style works in the same way as the wp_enqueue_script counterpart, but of course as you'd expect, enqueues stylesheets.. Here's a list of the enqueues i was able to ...


5

At a guess I'd say you're linking to your stylesheet with a relative url like so: <link href="wp-content/themes/my-theme/style.css" rel="stylesheet" /> so when you end up anywhere other than the home page it's looking at the full URL plus the path indicated to your stylesheet. Make sure your stylesheet URL begins with a slash if you're putting it ...


5

Scribu has an excellent article on loading scripts in WordPress. Basically, if you need a script to load on every page, use the following code (blatantly copied from said article): add_action('template_redirect', 'add_my_script'); function add_my_script() { wp_enqueue_script('my-script', plugins_url('my-script.js', __FILE__), '1.0', true); } (I ...


5

Well, it is the same form, but it is moved to another place in the DOM tree. So you could create one style for just .comments #respond, and one for .comments .comment #respond for the moved reply form.


4

You could tack it into header.php as you suggested (although this is not really the proper way to do it, it is best to use WPs enqueue function as described here). When do you need these? All the time? You can enqueue scripts and styles to be used all the time, or on an as-needed/per template basis ...


4

get_stylesheet_directory_uri() returns a value, it doesn’t print anything. So you have to use: echo get_stylesheet_directory_uri(); get_template_part() is just a wrapper for locate_template(). But the latter has one advantage: It returns the path of the file it has found. Try the following: $path = locate_template( 'sidebar-front.php', TRUE ); echo ...


4

You can do this using Wordpress's handy body_class() function. Depending on whether and how it is used in your theme, it may already be giving you what you need. Here's how to find out: Check the source of your page to see if the <body> tag in your category archive pages has any classes containing your category slug: category-apple, category-area, ...


4

Loading Scripts and Styles Dynamically Using Shortcode Advantages Does not search through all the posts every time the shortcode is called. Able to add styles as well as scripts dynamically only when shortcode is on the page. Does not use regexes since they tend to be slower than strstr() or strpos(). You could switch to regex if you need to accept args. ...


3

I don't know what your exact reason is for this, but you should scrap the idea of moving styles to the footer. If you though of a gain in speed, you might gain a unnoticable amount, if any, but that will be at the cost of other bigger things. Styles should always be added inside the <head></head> tag. The reason is that <style> tags ...


3

As @pieter-goosen and @birgire in other answer and comments, W3C specs do not allow css in footer, quote from specs page linked: A link element must have a rel attribute. If the rel attribute is used, the element is restricted to the head element. Aside from that, you should note that when you add css in footer, when someone opens your page it ...


3

Method 2 You can enqueue all of your stylesheets form the same place even controlling where the stylesheets load by means of template conditionals, which is convenient and prevents a lot of mess in your <head>. You can remove enqueued stylesheets if you need to via a plugin, for example. Enqueued stylesheets are child theme friendly as they can be ...


3

Assuming you have your child theme set up correctly, placing the following CSS in it which simply resets some of the preset values should get you all the way there. .et_pt_portfolio_entry { border: none; border-bottom: none; background: transparent; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; padding: 5px; ...


3

When your users really need 30 lines of custom CSS, your theme is flawed. Create a set of predefined styles instead (dark and light scheme, sans and serif fonts etc.) and prepare your main stylesheet for these cases. You can hook into body_class then and add the classes you need to get these styles. Adjustments for your users should be very minimal then. ...


3

You could filter body_class and add a time depending class: add_filter( 'body_class', 'time_body_classes' ); function time_body_classes( $classes ) { $classes[] = 'time-' . date( 'a' ); // time-am or time-pm $classes[] = 'time-' . date( 'H' ); // time-02 or time-17 return $classes; } Then you can make the CSS selector more specific: ...


3

WordPress doesn't add any CSS to your site, at least not by default, other than a little bit for the admin bar. For the most part, all of the CSS is added by your theme or by a plugin, though there might be an exception or two. WordPress functions do generate a lot of ids and classes though, but those shouldn't matter for a CSS reset. A 'reset' normalizes ...


3

Note that cForms is hooking into wp_head, and you're attempting to hook into wp_enqueue_scripts. The wp_enqueue_scripts hook is fired inside the wp_head hook (at priority 0, IIRC). So, your stylesheet is being enqueued at wp_head, priority 0, and the cForms stylesheet is being enqueued at wp_head, priority 10. Since it outputs later, it is taking precedence ...



Only top voted, non community-wiki answers of a minimum length are eligible