Support » Fixing WordPress » Stylesheet Changes Using Theme Options Page

  • I have a theme options page with stores value in the options table. I am then using these values to allow users to customise a stylesheet. The stylesheet is loaded in the head of the theme and brings values from the options table.

    To make the second stylesheet load WordPress function (notably get_option()) I am using this code in my themes functions.php file:

    add_filter('query_vars', 'add_new_var_to_wp');
    function add_new_var_to_wp($public_query_vars) {
        $public_query_vars[] = 'my_theme_custom_var';
        //my_theme_custom_var is the name of the custom query variable that is created and how you reference it in the call to the file
        return $public_query_vars;
    add_action('template_redirect', 'my_theme_css_display');
    function my_theme_css_display(){
        $css = get_query_var('my_theme_custom_var');
        if ($css == 'css'){
            include_once (TEMPLATEPATH . '/style-options.php');
            exit;  //This stops WP from loading any further

    I then call the stylesheet in the head of header.php below the themes stylesheet using this:

    <link rel="stylesheet" href="<?php bloginfo('url'); ?>/?my_theme_custom_var=css" type="text/css" media="screen" />

    It all works fine, but it seems to load the additional stylesheet (style-options.php) twice rather than once. Anyone any ideas?

    Thanks in advance for your time.

  • The topic ‘Stylesheet Changes Using Theme Options Page’ is closed to new replies.