Home / comment / Stop Disqus from outputting JS on anything but single posts or pages
  • How to Stop Disqus from outputting JS on anything but single posts or pages

    stop-disqus-outputting-js-anything-single-posts-pages-wordpress

    Disqus outputting JS on parts of your wordpress website you don’t want? Adding this snippet to the functions.php of your wordpress theme will only output JS on is_singular posts or pages where comments are available.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    add_action( 'wp_head', 'tgm_tame_disqus_comments' );
    function tgm_tame_disqus_comments() {
    	if ( is_singular( array( 'post', 'page' ) ) && comments_open() )
    		return;
    	remove_action( 'loop_end', 'dsq_loop_end' );
    	remove_action( 'wp_footer', 'dsq_output_footer_comment_js' );
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    wp_footer, wp_head, add_action, remove_action, _e, comments_open, is_singular, wp,