css – Create a page template without theme styles and scripts, how?


Following this tutorial: “Add Page Templates to WordPress with a Plugin” I made a plugin that generates two templates using Bootstrap and many of its components. Templates work well but, unfortunately, theme interference ruins both aesthetics and some functionality. If I don’t use the get_header() and get_footer() functions in the template files and I write the entire template as if it were an HTML 5 page I solve the problem but I lose the ability to inject CSS and JavaScript through the wp_enqueue_style() and wp_enqueue_script().
Furthermore, the get_header() and get_footer() functions also insert menus and links into the template that I don’t want.

How do I make a template with all the possibilities of WordPress but without having to suffer the interference of the theme?

I tried writing a function that should remove every CSS and JS before injecting my own but seems it doesn’t work.

function remove_theme_stuff() {
if ( is_page_template( 'template-ccwetd-secretariat-dashboard.php' ) ||
             is_page_template( 'template-ccwetd-student-dashboard.php' ) ) {

            $wp_scripts = wp_scripts();
            $wp_styles  = wp_styles();
            $themes_uri = get_theme_root_uri();

            foreach ( $wp_scripts->registered as $wp_script ) {
                if ( strpos( $wp_script->src, $themes_uri ) !== false ) {
                    wp_deregister_script( $wp_script->handle );
                    wp_dequeue_script( $wp_script->handle );

            foreach ( $wp_styles->registered as $wp_style ) {
                if ( strpos( $wp_style->src, $themes_uri ) !== false ) {
                    wp_deregister_style( $wp_style->handle );
                    wp_dequeue_style( $wp_style->handle );

icolumbro 4 months 2021-06-25T10:14:48-05:00 0 Answers 0 views 0

Leave an answer