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


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


9

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


6

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

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

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

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

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

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

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

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


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

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

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

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



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