Content last modified Monday 6 March 2017
hop to #bottom
Current version:
About It:
Get it:
Rate it:
  • Helpful?
  • 0 Yes
  • 0 No
Flag it:

If you'd like to provide updated information and do not have access to directly edit, please contact the site admin; thanks!


Disclaimer: Ideally, this should/could be accomplished with Mark Norton’s mdn_if_custom plugin. But because that plugin is designed for use within articles and depends on variables that do not yet exist at the time non-article forms are parsed in Textpattern ($thisarticle & $pretext), this separate plugin was written and successfully sidesteps that issue.

Allows for conditional stylesheets on a per-article basis. Inspired by Khoi Vinh at Subtraction

There are three small, non-hack prerequisites for this to function:

  • You must have a custom field available (defined in textpattern/lib/admin_config.php) in order to store the ‘true’ (or any non-empty) value, signaling that an article is using custom CSS.
  • You must name the CSS file according to the article ID number. For instance, article 63 would use ‘63.css’.
  • You must store all the CSS files in the same location.


Number corresponding to the custom field you’re using. Any value whatsoever stored inside that custom field for an article will be seen as a boolean TRUE value. I just use a custom field named ‘CSS’ and type ‘1’ if the article uses custom CSS.
OPTIONAL. A value such as ‘/css’ or ‘/assets/css’ (requires leading slash). If no path, default is relative to document root.
OPTIONAL. By default, the stylesheet link tag will be output in XHTML format. By setting this value to ‘1’ you may opt for HTML.
OPTIONAL. Allows for media types such as screen, projection, print, etc.
OPTIONAL. Allows for assigning a title to the stylesheet.


This plugin is designed to be used within your main page template (or whichever form you use that contains the document <head>). Just simply put in the plugin tag after your normal style link tags and it will output article-specific link tags if the corresponding custom field has a value stored in it.

<txp:ajw_custom_css field="1" path="/css" />
<link rel="stylesheet" type="text/css" href="/css/63.css" />

<txp:ajw_custom_css field="1" nohtml="1" />
<link rel="stylesheet" type="text/css" href="/63.css" >

Changes in version 0.2

  • Add support for ‘title’ attribute
  • Add support for ‘media’ attribute
Article Request Count:
Initially released:
15 January 2005
Posted here:
11 Apr 2005
Article modified:
06 Jan 2007

If there is a comment form at the Information URL, you may want to leave your comments/questions there or at the Forum thread for quicker feedback. Otherwise, comment away:

Commenting is closed for this article.

Subscribe to this article's comments RSS feed. [ ? ]   View Recent Comments across the site.

You know you want to visit the Archives.




There are also tag clouds, 'cause those are fun.
Published with Textpattern