[Support request] Deregister JS and CSS entire site except on all posts

Home Forums Support [Support request] Deregister JS and CSS entire site except on all posts

Home Forums Support Deregister JS and CSS entire site except on all posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #999753
    webcréateur

    Hi there,

    Can you pls give me a hint how to disable/deregister JS (wp_deregister_script) and CSS (wp_dequeue_style) entire site except on all posts? Is this possible withe GP Elments?

    Best Regards.

    #999860
    David
    Staff
    Customer Support

    Hi there,

    can you explain why you would want to do this?
    The theme relies on whatever CSS or JS it loads, without it the site will break.

    #999882
    webcréateur

    We have to use a Plugin which seem to make the website very slow.

    This snippet e.g. restrict loading of a calendar Plugin on all pages except on Page “Events”:

    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
    if ( !is_page('Events') ) {
    wp_deregister_script( 'wpng-calendar' );
    wp_deregister_script( 'date-js' );
    wp_deregister_script( 'thickbox-js' );
    wp_deregister_script( 'jquery-js' );
    wp_deregister_script( 'wiky-js' );
    }
    }

    But what I need is to load the Plugin on single Posts and restrict loading anywhere else.

    #999898
    David
    Staff
    Customer Support

    So you should be able to change the conditional to not posts ie. this:

    !is_page('Events')

    becomes:

    !is_single()

    This article explains how to add PHP:
    https://docs.generatepress.com/article/adding-php/

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.