31 Responses

  1. Ptah Dunbar
    Ptah Dunbar Published |

    Ah, neat little trick. That’s something I’ve had to explain to several users when they were interested in trying to add a custom stylesheet for page templates etc. (even though a simple .page-template-archives rule would suffice).

  2. Jeremy
    Jeremy Published |

    Useful, simple to implement and well explained: another great tip of yours, thank you!

  3. Peter Kahoun
    Peter Kahoun Published |

    Could you provide an example when replacing whole stylesheet is more “better” than adding some overriding rules?

  4. Adam W. Warner
    Adam W. Warner Published |

    Can someone explain what the 10 and 2 are doing in this line?:

    add_filter( 'stylesheet_uri', 'my_stylesheet', 10, 2 );
  5. Ptah Dunbar
    Ptah Dunbar Published |

    @Adam – 10 is the priority that my_stylesheet will run. So that means it has to wait until everything less than 10 is run before this function gets executed. 2 is the number of arguments my_stylesheet accepts ($stylesheet_uri and $stylesheet_dir_uri).

  6. Adam W. Warner
    Adam W. Warner Published |

    Thanks Ptah, now I fully understand what’s happening in the above code:)

  7. links for 2009-07-28 | Links | WereWP
  8. fb
    fb Published |

    I would also agree with the comment here http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet#comment-143544

    As you have all of your themes so well coded, why do we need to have additional css files?

    We can just add over riding css rules.. as most of us cache the css files locally (on clients sites) why make them d/l a new one..

    Maybe I’m just barking up the wrong tree, Justin please enlighten me ( as you have thankfully done many times before)


  9. WordPress Watch » Blog Archive » How to use multiple stylesheets in one WordPress theme
  10. fb
    fb Published |

    Ok sure still seems a bit extreme, but understand that it could come in handy


  11. Peter Kahoun
    Peter Kahoun Published |

    @Justin Got it now, thanks. Actually, you could go even more into extreme and load even entirely different theme… So the particular Page would look like a separated website. (Just thinking aloud…)

  12. fb
    fb Published |

    Re: http://justintadlock.com/archives/2009/07/27/contextually-changing-your-themes-stylesheet#comment-143907

    loading a completely different theme, per page or post, this was (not sure if it still works) with all-in-one seo, you had the possibility of choosing what theme you wanted to use on a per-page/post basis, just my two cents…

  13. Robert Joe
    Robert Joe Published |

    Indeed a great tip this, I really love you for this.

  14. WordPress Weekend Resources - July 31, 2009 | Theme Lab
  15. Wordpress Blog Services - WordPress Weekend Resources - July 31, 2009
  16. Chris
    Chris Published |

    For a real-world example, would this be a practical alternative to creating a separate home.php file, if I would like to remove the sidebar from my static front page?

  17. Wordpress Wednesday: 50 Links & Resources from around the web | Wordpress Guerrilla
  18. Modern Warfare 2
    Modern Warfare 2 Published |

    Thanks Chris !! I was all messed up trying to use CSS 🙁

  19. rexsky
    rexsky Published |

    hey Justin,great job.I just learn div and css last month..thanks for your sharing…learned a lot from your blog….again thanks…

  20. Dan Smart
    Dan Smart Published |

    Thanks for the post. I’ve been looking for a solution like this, however I’m still trying to create a solution that doesn’t require you to have a list of pages in the function – it would be nice to be able to grab this from the custom page or something similar so that it’s totally extensible rather than dependent on you adding to the list of pages with is_page().

    Any thoughts?

  21. Sam Lehti
    Sam Lehti Published |

    This really is handy looking example. Never knew it was possible with WP itself. Have been using thesis to get things done but somedays want to use another theme and if it works with every theme I could use it instead of hacking every css file by hand.

  22. andri
    andri Published |

    I need more tips about hybrid theme… thanks for this tips 🙂

  23. Scott Pelland
    Scott Pelland Published |

    Thanks, Justin. I’ve been looking for a solution just like this for some time. I also was wondering if you had given any thought to Dan’s question above?

  24. VB .Net Tutorial
    VB .Net Tutorial Published |

    Thanks the idea of switching the styles as per the contxt is nice. Have you ever experienced issues with cache when switching themes.

    How about bypassing the cache. I always had problems if the different stylesheet is already in cache, then the theme wont be switched properly. I guess i need some sort of different names to store into cache.

  25. Will
    Will Published |

    How about trouble with caching? will it cause trouble. One of my asp.net themes always have trouble with caching. Any resolutions?

  26. Thomas Gam Nielsen
    Thomas Gam Nielsen Published |

    Hi guys

    Is it possible to load a specific style file for a page and all the children pages related to that page?

    if ( is_page( 'about' ) ) (AND THEN SOMETHING WITH ALL CHILDREN PAGES)
    		$stylesheet_uri = $stylesheet_dir_uri . '/style-about.css'; 

    Just wondering…

    // Thomas

  27. Chris
    Chris Published |

    I am hitting a wall trying to do this (in 3.2.1). I get the following notice:Undefined variable: stylesheet_uri and neither of the two stylesheets is loading – instead when I look at the source code I see the default style.css? I also don’t understand the following:
    $stylesheet_uri, $stylesheet_dir_uri –
    do I need to define each as:
    $stylesheet_uri = stylesheet_uri();
    $stylesheet_dir_uri = stylesheet_dir_uri();
    Please help – this is actually the best solution for me since I want to change the layout depending on the page… thanks!

  28. Chris
    Chris Published |

    Hi again, after reading Thomas’ post, I wonder if I need to be using the hybrid theme – I am developing my own

  29. Changing stylesheet depending on custom taxonomy terms My Wordpress Tips

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.