Opened 14 years ago
Closed 12 years ago
#11006 closed enhancement (worksforme)
Theme Preview on Admin Page
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | normal | Version: | 2.8.4 |
Component: | Administration | Keywords: | |
Focuses: | Cc: |
Description
I have trouble with my theme Constructor - I write following code for register stylesheet generated by PHP:
wp_enqueue_style( 'constructor-custom-style', get_option('home').'/?theme-constructor=css');
But this is code doesn't work with theme preview, because correct url for preview is '/?theme-constructor=css&preview=1&template=constructor'
I found simple solution, but this is requried changes of Wordpress source code in file wp-includes/theme.php:
function preview_theme_ob_filter( $content ) { // apply new filter $content = apply_filters('preview_theme_ob_filter', $content); // add filter for preview content return preg_replace_callback( "|(<a.*?href=([\"']))(.*?)([\"'].*?>)|", 'preview_theme_ob_filter_callback', $content ); }
I can use this is filter in my function.php:
function constructor_preview($content) { $link = add_query_arg(array('preview' => 1, 'template' => get_template()), '?theme-constructor=css'); $content = str_replace('?theme-constructor=css', $link, $content); return $content; } add_filter('preview_theme_ob_filter', 'constructor_preview');
Change History (2)
Note: See
TracTickets for help on using
tickets.
There's not enough information here for me to go on.
It also looks like an edge case:
wp_enqueue_style( 'constructor-custom-style', get_option('home').'/?theme-constructor=css');
means you're loading WordPress *again* just to generate CSS. This is bad.http://ottopress.com/2010/dont-include-wp-load-please/ (Use the Right Way the First, not the Second).
You should probably just capture when it is a preview and add the query args yourself to the wp_enqueue_style() call.