1

Let me explain what Im trying to do. Im creating a plugin that will have a main page like a dashboard that will be used to manage the public facing side of the plugin. Just think like a separate app inside a normal WordPress site.

That page needs to be completely separate from user theme as will be totally custom. Admin bar will be used, nothing else.

My first thought was to create a page with a custom template (already done that) and second step would be to remove all actions from wp_header + wp_footer and remove all scripts and styles that are not WordPress core.

So currently Im stuck on step 2 and before going forward Im wondering if there is another way to do this that Im missing.

2 Answers 2

1

It seems a little odd to only offer the admin bar for a page, but the easiest solution I can think of would be to use conditional functions to deregister scripts/styles and create custom template files for this specific page. Unfortunately, you'll have to figure out all the styles/scripts that are loaded

add_action('init', 'remove_all_the_things');

function remove_all_the_things() {

  if (is_page(123)) {
    wp_dequeue_style('main');
    wp_dequeue_script('jquery');
    // etc
    // remove other actions/filters as well
  }
}

and you can create a custom header/footer with

header-empty.php & footer-empty.php

calling get_header('empty'); & get_footer('empty'); in your page template

Reference:

https://codex.wordpress.org/Function_Reference/is_page https://codex.wordpress.org/Function_Reference/wp_dequeue_script https://codex.wordpress.org/Function_Reference/wp_dequeue_style https://codex.wordpress.org/Function_Reference/get_header https://codex.wordpress.org/Function_Reference/get_footer

1
  • Joshua this is a plugin that will work on different sites, so what I need is a way to remove all scripts and styles (except core ones like jquery). Manually removing scripts or actions is not an option
    – chifliiiii
    May 7, 2015 at 0:32
0

This is what I´ve done so far, I won't mark as correct answer yet in case there is a better approach that Im not aware.

add_action('wp_enqueue_scripts',array( $this, 'remove_all_actions'), 99);
public function remove_all_actions(){
        if( 'custom-template.php' != get_page_template_slug( get_queried_object_id() ))
            return;
        global $wp_scripts, $wp_styles;

        $exceptions = array(
            'admin-bar',
            'jquery',
            'query-monitor'
        );

        foreach( $wp_scripts->queue as $handle ){
            if( in_array($handle, $exceptions))
                continue;
            wp_dequeue_script($handle);
        }

        foreach( $wp_styles->queue as $handle ){
            if( in_array($handle, $exceptions) )
                continue;
            wp_dequeue_style($handle);
        }

        // Now remove actions
        $action_exceptions = array(
            'wp_print_footer_scripts',
            'wp_admin_bar_render',

        );

        // No core action in header
        remove_all_actions('wp_header');

        global $wp_filter;
        foreach( $wp_filter['wp_footer'] as $priority => $handle ){

            if( in_array( key($handle), $action_exceptions ) )
                continue;
            unset( $wp_filter['wp_footer'][$priority] );
        }

    }

Your Answer

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

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