Add Custom Styles for a Single Entry in Movable Type using PHP

| No Comments

Stumbled across another way to Add Custom Styles for a Single Entry in Movable Type from the entry Individual Style on Khoi Vinh’s Subtraction.com.

  1. Create a css file using the same basename as your entry, but with a .css extension
  2. Place this bit of PHP in the <head> element next to your other stylesheet links:

    <?php
    // check to see if a css file with the same name as the permalink exists,
    // if so print a link to it
    if (file_exists("<$MTEntryPermalink$>.css")) {
        print '<link rel="stylesheet" type="text/css" href="<$MTEntryPermalink$>.css" />';
    }
    ?>
    

This is great if there are many rules to add and/or if there is a need to edit the css independently from the publishing of the entry.

For just a few simple rules I’d still add the rules inline. This has the benefit of keeping the styles directly associated to the content being styled.

Leave a comment