• I have a page that is different from all other pages on the site. It is the primary user-viewed page, and doesn’t need many of the assets loaded from wp_head(). What is the most effective (and future-proof) way to handle this?

    I need:
    Just a specific set of JS/CSS a couple of plugins ONLY. I don’t even need CSS/JS from the theme, since it’s a standalone page.

    There is so much extra, being loaded. 300k before content. I want to strip as much as possible.

    Thanks

Viewing 1 replies (of 1 total)
  • How are you loading the js scripts and css of your theme? The best way to do this is through the hooks wp_enqueue_style() and wp_enqueue_script(), if you are doing this way then you can check what page the user is and only load the necessary scripts.

    For example, suppose you need to carry two CSS files and JS on the homepage, but not in need of any of them internal, I could do something like:

    function sotero_enqueue_scripts() {
    if( is_home() ) {
    wp_enqueue_style( 'my_slug_1', get_template_directory_uri() . '/css/css_1.css', array(), null, 'all' );
    wp_enqueue_style( 'my_slug_2', get_template_directory_uri() . '/css/css_2.css', array(), null, 'all' );
    wp_enqueue_script( 'my_slug_3', get_template_directory_uri() . '/js/js-3.js', array(), null, true );
    }
    }

    That would be the way I would, but if you are calling the CSS and JS directly in header.php or footer.php directly create a page-slug.php and makes your HTML normally, without calling the files you do not need.

Viewing 1 replies (of 1 total)
  • The topic ‘Single page template – only need basic css/js. How to restrict wp_head() load?’ is closed to new replies.