Tag Info

Hot answers tagged

19

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


14

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


13

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


11

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


9

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


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

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

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


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

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

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

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


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

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


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

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

EAMann is correct, you don't have to use the style.css file for all your CSS. For versioning the style sheet and other files in your theme you can add this to your functions.php file function fileVersion($filename) { // get the absolute path to the file $pathToFile = TEMPLATEPATH.'/'.$filename; //check if the file exists if ...


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

For modify this output you can use that filter: function wpse51581_hide_type($src) { return str_replace("type='text/css'", '', $src); } add_filter('style_loader_tag', 'wpse51581_hide_type'); You can see this hook into wp-includes/class.wp-styles.php


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

Previous versions of WordPress didn't really provide a good means to conditionally enqueue stylesheets and JavaScript within a plugin (i.e. only when needed). So most plugin authors enqueued both on every WordPress init/load, even if the plugin wasn't being used on a given page. Current versions of WordPress allow for enqueuing later in the flow so you you ...


3

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


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


2

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


2

It depends on your theme. With most themes you'll have to manually edit the CSS to do this. But some themes have control panels that allow you to make changes to the design without editing the code. If you'd rather not write code but would like to make changes to your site, I'd suggest using a theme with design options. Some are very simple, just a few ...


2

Well, you could simply use style.css as the place where you call the version you want. Simply put @import url("style-1.css"); Then when you upgrade a version, just edit it to be: @import url("style-2.css"); As for saving versions, have you considered using a Subversion, or git? Then you can have a complete track record of your stylesheet. It's possible ...


2

There's a part in your header template that's already doing conditional loading: <?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?> This code loads the JavaScript for comments into the queue; WordPress then loads all of the scripts when it fires the wp_head() trigger. My recommendation would be to use your functions.php file to ...


2

First issue - you have dependency backwards. Depending on something means loading after dependency, while you want earlier. Second issue - theme's stylesheet doesn't actually use enqueue, it is usually codded directly in header.php file of theme. And since it seems to come before wp_head() call - you have no hook to ensure your stylesheet is above it. So ...


2

Yes there is. You can add this to your themes header. <?php if(is_home()){ // we are on the home page echo '<link rel="stylesheet" src="your_stylesheet" />'; } ?> You can also use other conditional tags to find out if you are on nearly every type of WordPress page. Conditional Tags Following on from the comments below, this would ...



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