WordPress.org

Forums

Stylesheet Changes Using Theme Options Page (1 post)

  1. Equal Web Creative
    Member
    Posted 5 years ago #

    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:

    <?php
    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 5 years ago by Equal Web Creative
  • This topic is not resolved
  • WordPress version: 3.0