12 Jan 2009, 10:25pm
Projects:
by

33 comments

  • A Cleaner Way To Customise WordPress Theme Styles

    The most frequently asked question from Emptiness Theme users was about customising the styles (font, color, width, etc) and the header image of the theme, and I usually answered by giving them some pointers to which file to modify and where. The problem was that most WordPress usersĀ  would make the modifications directly against the theme files.

    The downside of such approach is that the custom code would end up buried within the theme, which users won’t remember few months down the line. And this will then discourage them from upgrading the theme in order to avoid overwriting the customisations accidentally.

    A cleaner approach to customise a theme is by isolating the custom code away from the original theme code. Having said that, I would like to encourage my theme users to start practicing this approach. Here’s what you need to do:

    1. Install MyCSS Plugin, read the documentation on how to use the plugin. Note: you might encounter an error complaining about ‘my.css file not found’, to fix this, you need to create my.css file under mycss plugin directory and give it a proper permission (644 will do).
    2. When you need to customise a style, do it on my.css file. CSS code in this file will take precedence over the theme’s own style.css .

    For example, to change the font-family of the sidebar headings, I added these lines to my.css file:

    h3 {
        font-family: helvetica, sans-serif;
    }
    

    That’s it. I didn’t modify any of the theme code. The catch here is of course we have to be careful not to accidentally delete my.css file.

    I don’t know why WordPress doesn’t have this custom CSS feature as part of vanilla WordPress installation. I think this would be very useful when they finally provide easy theme upgrade just like the way upgrading plugins is done.

    As for MyCSS Plugin itself, it would be nice if it allows me to customise the location of my.css file so I can put it external to the plugin directory. And how about storing the content of my.css in the database so it can be persisted between plugin versions? Another nice improvement would be to provide the ability to upload files, handy for custom images.

     

    Recent Posts

    Recent Comments

    • Cliffano Subagio: Good to hear about your opportunity to visit Japan, I’m sure you will have a great...
    • Kayla: I’m going to Japan for two week this summer. Our sister city is Tsubame, Japan and my school has an...
    • poseidonfu: thanks,Very effective
    • anonymous: I really enjoyed both the last lecture and the book. I don’t think that theres anyone that I look up...
    • dioni: The thing I hate about HK is how people shove and push in the queue. Can’t they be civilized?!! I kept...

    Most Commented Posts

    Linkroll