Tag Info

Hot answers tagged

21

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 ...


15

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 ...


14

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

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 ...


12

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') . ...


8

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 ...


7

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: ...


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.


5

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 ...


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, ...


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

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 ); } ...


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

Style.css is required for your WordPress theme. That's where WordPress gets the theme name and meta information for the Appearance >> Themes menu from. That said, you don't actually have to use style.css in your theme at all. I know of several readily available themes that don't use it, and I only use it in a handful of my custom designs. In header.php ...


3

Drop this in your theme's functions.php file: function my_cool_style_versioner( $style ){ return str_replace( '/style.css', '/style-1.css', $style ); } add_filter( 'stylesheet_uri', 'my_cool_style_versioner' );


3

Yep, I experienced that under some network configurations https links fail (my case was behind proxy server). You can use Core Control plugin to test available HTTP transports and disable glitchy one. In my case bumping transport to curl solved issue.


3

There's a lot of ways you could go with this. I might enqueue the style in your theme's functions.php dependent on a file_exists() check. $your_css_file_path = "/path/to/file"; if ( file_exists($your_css_file_path) ) { wp_register_style('your_theme_stylesheet', $your_css_file_path); wp_enqueue_style( 'your_theme_stylesheet'); } Here's the relavent ...


3

the right way would be using wp_enqueue_script for scripts and wp_enqueue_style for styles.


3

Absolutely! Into functions.php, like you said. I'll call it cache_busting_styles because I like how it sounds. First, you set up the style via wp_enqueue_style, then call it during the action hook wp_print_styles, Also, you'll want to set up a variable and pass it in there as the version number as well: function cache_busting_styles() { //however you ...


3

To enqueue extra styles you should place the following code in your functions.php function my_custom_styles() { wp_enqueue_style( 'custom-style', get_stylesheet_directory_uri() . '/custom_style.css'); } add_action( 'wp_print_styles', 'my_custom_styles' );


3

in your theme's functions.php, look for this: // The height and width of your custom header. You can hook into the theme's own filters to change these values. // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); ...


3

I would put all the common css in the theme's style.css, and create separate stylesheets for the color options. I would also put color options in their own folder with the images for that style. This way you can keep the filenames the same between color options to make maintaining the code a little easier. If you wanted to separate common.css from ...


3

add_filter('style_loader_tag', 'html5_style_tag'); function html5_style_tag($tag) { return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag); }


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 ...



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