$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - Is it possible to disable a theme programmatically?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - Is it possible to disable a theme programmatically?

matteradmin10PV0评论

I'm building a plugin that loads iframes to display some content. I have specific scripts & styles for that content and would thus like to ignore the active theme when loading those templates; both to save loading time & to avoid CSS conflicts.

I know it is possible to dequeue all scripts & styles using the wp_enqueue_scripts and wp_enqueue_scripts hooks.

Thing is, as my plugin do also queue some scripts and styles, it would be cleaner to find a way to disable the current theme uphill rather than to quibble to unload some files and not others.

SO: is it possible to ignore / unload the current theme on certain pages / templates ?

Thanks

I'm building a plugin that loads iframes to display some content. I have specific scripts & styles for that content and would thus like to ignore the active theme when loading those templates; both to save loading time & to avoid CSS conflicts.

I know it is possible to dequeue all scripts & styles using the wp_enqueue_scripts and wp_enqueue_scripts hooks.

Thing is, as my plugin do also queue some scripts and styles, it would be cleaner to find a way to disable the current theme uphill rather than to quibble to unload some files and not others.

SO: is it possible to ignore / unload the current theme on certain pages / templates ?

Thanks

Share Improve this question asked Jan 16, 2019 at 9:33 gordiegordie 4925 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

here is no specialized hook for this. However the hook switch_theme should work for you.

/**
 * Switches current theme to new template and stylesheet names.
 *
 * @since unknown
 * @uses do_action() Calls 'switch_theme' action on updated theme display name.
 *
 * @param string $template Template name
 * @param string $stylesheet Stylesheet name.
 */
function switch_theme($template, $stylesheet) {
    update_option('template', $template);
    update_option('stylesheet', $stylesheet);
    delete_option('current_theme');
    $theme = get_current_theme();
    do_action('switch_theme', $theme);
}

So you should write custom function that deactivate the theme via hook and activate back, if your done with your task.

add_action('switch_theme', function($theme){
    if ( 'Your_Theme_Name' == $theme )
    {
        // do something.
    }

    // do others.

    return;
});
Post a comment

comment list (0)

  1. No comments so far