• Resolved b49015

    (@b49015)


    Hi,

    I am using this plugin and I really like it very much, but I am seeing one issue is that
    I am using plugin at only one page https://zindagiterenaam.com/audio-shayari/ but it load its style and scripts in all pages which is slowing down my website performance.
    Can you please help me how can I remove plugin’s code from all other unwanted pages and posts?

    The page I need help with: [log in to see the link]

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

    (@vedathemes)

    Hi there,

    Thanks for trying podcast player.

    Following steps should help you to stop loading podcast player scripts and styles.
    1. Copy and paste following code at the end of your child theme’s functions.php file (If you are not using child theme, you can use Code Snippets plugin to insert custom codes).

    add_action( 'after_setup_theme', function() {
    	if ( is_admin() ) {
    		return;
    	}
    
    	$id = get_the_ID();
    
    	// Return if post ID not available.
    	if ( ! $id ) {
    		return;
    	}
    
    	// Replace 6884 with comma separated list of page/post ids ONLY where podcast player is to be displayed.
    	if ( in_array( $id, array( 6884 ) ) ) {
    		return;
    	}
    
    	// Remove podcast player scripts.
    	add_action( 'wp_print_scripts', function() {
    		wp_dequeue_script( 'podcast-player-mmerrorfix' );
    	} );
    	add_action( 'wp_print_styles', function() {
    		wp_dequeue_style( 'pppublic' );
    	} );
    	add_action( 'wp_footer', function() {
    		if ( class_exists( 'Podcast_player\Frontend' ) ) {
    			remove_action( 'wp_footer', array( Podcast_player\Frontend::get_instance(), 'enqueue_scripts' ) );
    			remove_action( 'wp_footer', array( Podcast_player\Frontend::get_instance(), 'svg_icons' ), 9999 );
    		}
    	}, 0 );
    } );

    2. Notice number 6884 in above code. It is page ID of your page where you are using podcast player. If you ever change the page/post or display podcast player on more than one page, just replace or add page ID to above code.

    NOTE: Always backup your site before making PHP changes.

    Please inform if you need more help on this OR if any other help is required.

    If you like the plugin, kindly consider giving five star rating.

    Thanks,

    • This reply was modified 4 years, 9 months ago by Veda.
    • This reply was modified 4 years, 9 months ago by Veda.
    Thread Starter b49015

    (@b49015)

    Thanks, @vedathemes

    your above code is working, But the hook “after_setup_theme” is not right. during “after_setup_theme” there will be no ID return from get_the_ID().
    In my case I have replaced it with “wp” and now everything is working fine.

    Thank you.
    I really like this plugin. and I have given the 5 star already. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to remove scripts and styles from unwanted pages’ is closed to new replies.