Wordpress: switch CSS stylesheets

It is possible to switch a theme’s CSS, depending on whether widgets are enabled or not - whether, like a lot of things in programming it is a good idea to do this, just because you can, is another matter…

This is the code - in the head section of header.php and after the main stylesheet of the theme, always style.css, has been linked to.

<?php if (function_exists(’dynamic_sidebar’)) { ?>

<link rel=”stylesheet” href=”<?php bloginfo(’stylesheet_directory’); ?>/widgets.css” type=”text/css” media=”screen” />

<?php } else { ?>

<link rel=”stylesheet” href=”<?php bloginfo(’stylesheet_directory’); ?>/nonwidgets.css” type=”text/css” media=”screen” />

<?php } ?>

But it does rely on the WordPress foible of not being able to switch widgets off completely (except by deleting code).

Far better is to struggle on with the XHTML/CSS until you get something that is the same for both and don’t need 2 stylesheets in the first place…

Bookmark:
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Google
  • Facebook
  • Furl
  • NewsVine
  • Reddit
  • StumbleUpon
  • Sphinn
  • Technorati

1 Comment

  1. élet és könyvtár » Blog Archive » Vasárnap reggeli WordPress és dizájn linkek — April 13, 2008 @ 10:37 am

    […] Ez az aprócska kis kód a widgetektől függően tölti e a stíluslapokat, hasznos. És aki ennél jobban szeret hekkelgetni (és a Photoshop sem idegen tőle), annak itt van pár inspiráló kommentdizájn. Ha pedig ennyire azért nem akarunk mélyen turkálni a dolgokban, de van igény a szépre és hasznosra, annak az egyik legjobb kiegészítő az admin felületre (dropdown menü, lelőttem a poént). Esetleg ha valaki egy fullos CMS-t akar fargni a WordPresséből (ki nem? ;), annak egy 10 pontos lista a musthave pluginekből. […]

RSS feed for comments on this post. TrackBack URI

Leave a comment