• Anonymous User 14018805

    (@anonymized-14018805)


    Hi,
    it is possibile to enqueue javascript/CSS/fonts only on a selected page?

    thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    I believe it should be possible with a custom code, if you know the Page ID you want to include the scripts only.

    I haven’t tried this solution, but something like this should work:

    function asp_cond_dequeue_script() {
      $page_id = 123; // Change this to the page ID you want
      
      global $post;
      if ( !isset($post->ID) || $post->ID != $page_id ) {
        $scripts = array(
          'wpdreams-asljquery',
          'wpdreams-gestures',
          'wpdreams-gestures',
          'wpdreams-highlight',
          'wpdreams-scroll',
          'wpdreams-ajaxsearchlite',
          'wpdreams-asl-wrapper'
        );
        $styles = array(
          'wpdreams-asl-basic',
          'wpdreams-ajaxsearchlite',
          'wpdreams-gf-opensans'
        );
      
        // ------------------------------
        foreach ($scripts as $script)
          wp_dequeue_script( $script );
          
        foreach ($styles as $style)
          wp_dequeue_style( $style );
      }
    }
    add_action( 'wp_print_scripts', 'asp_cond_dequeue_script', 100 );

    Use it in the functions.php file in your theme folder. Change the $page_id variable to the post or page ID you want to use the scripts and styles on.

    Thread Starter Anonymous User 14018805

    (@anonymized-14018805)

    Thanks, with an high priority 9999 it works!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Javascript dequeue Optimization’ is closed to new replies.