1

I created an options page for my theme, where I can manually edit the CSS.
Lets say I change the CSS in the options page for the <H1> tag, so it will now change it on the front-end.
What I want to also do is have it change in the visual editor.

I have added the function

add_editor_style(style.php);

and in the style.php I have it saying in the top

<?php
header('Content-type: text/css');
?>

so it recognizes the file. But now I can't get the options dynamically...

How should I achieve this?

EDIT

this is in the functions.

add_filter( 'mce_css', 'cnote_visual_css' );
function cnote_visual_css() {
    return get_bloginfo('template_directory') . '/cnotethegr8/global-style.php';
}

this is the global stylesheet

<?php
header('Content-type: text/css');
global $shortname;
?>

h1 { <?php echo(get_option($shortname.'_style_h1')); ?> }

when i echo $shortname nothing shows...

4
  • Do you have a problem loading that style.css file in the editor, or do you have a problem reading your plugin settings in that file? Can you edit your question to make this clear?
    – Jan Fabry
    May 27, 2011 at 11:55
  • Could this be due to tiny mce and your browser caching the old stylesheet? Maybe try adding a random generated number to add_editor_style("style.php?v=".rand());
    – Scott
    May 27, 2011 at 13:27
  • @Brady: So i thought it was to the version generator, but i fixed that problem. Basically the php options arent being recognized. For instance if i echo get_bloginfo('name') nothing is printed. but the php itself does work with a test of $this = 'hello'; echo $this; May 27, 2011 at 13:50
  • Ok I think I might know your answer but need to see your code to say for certain. Please post your dynamic stylesheet code as the way you think it should be.
    – Scott
    May 27, 2011 at 13:56

1 Answer 1

1

The reason why this isn't working is because the WordPress core isn't loaded when this dynamic style sheet is loaded. get_option() hasn't been defined yet.

What you need to do is load WordPress at the top of your dynamic stylesheet:

<?php
include("../../../wp-load.php");
?>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.