• Can anyone tell me if it’s possible to exclude plugins or scripts from specific pages?

    For example, there are many plugins I use for posts but which don’t need to load on say, my home page. I’d like to exclude them to keep unnecessary weight off the page (as well as decrease the possibility of conflicts with other things I’ve got going on with my front page as it’s very customized)

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I believe it depends on the type of plugin you’re using. For instance, if it’s a plugin that adds content somewhere, you could easily get around having it not display on your homepage by wrapping the plugin code (which you publish in the theme) in something like <?php if(!is_page('home')) { plugin code } ?>.

    If the plugin injects itself into the theme using hooks, then you’ll most likely need to directly modify the plugin’s behaviour if it doesn’t provide an option in the admin panel. That I would not recommend unless you’re comfortable working with PHP and understand how WP’s internals work.

    HTH.

    Thread Starter chanzero

    (@chanzero)

    Thanks for the response!

    In this particular case I’m talking about Audio Player, which doesn’t seem to have any code I can wrap in an IF statement — good suggestion though ??

    I might just have to try and look at the plugin code itself (although it’s probably a bit beyond my PHP abilities)…

    Hi Chanzero.
    It’s doubtful that you’re still looking for a solution to this issue, but since someone else might, here is how I solved it for the Audio Player plugin.

    NOTE: this is in no way considered an ideal or elegant solution and requires the editing of the plugin’s code (which I personally do not like having to do); but in the absence of other options it, at least, works.

    STEP 1 – Editing the Audio Player Plugin File
    On (or around) line 142 of audio-player.php, I edited the line that read:

    add_action("wp_head", array(&$this, "addHeaderCode"));

    by adding a “//” (effectively “commenting out” the line) to result in

    // add_action("wp_head", array(&$this, "addHeaderCode"));

    This removes the code that the Audio Player plugin inserts in the head of every WordPress page.

    STEP 2 – Adding the required Audio Player Code to Specific Pages

    To make the audio player work on the pages you require, you need to add back in the required code to the head of those specific pages.

    As such, I used an IF/ELSE statement in the header.php file of my active theme as follows:

    <?php
     if (is_page('###')) {
    	echo '<script type="text/javascript" src="https://www.YOURDOMAIN.org/wp-content/plugins/audio-player/assets/audio-player.js?ver=2.0.4.1"></script>
    <script type="text/javascript">AudioPlayer.setup("https://www.YOURDOMAIN.org/wp-content/plugins/audio-player/assets/player.swf?ver=2.0.4.1", {width:"290",animation:"yes",encode:"yes",initialvolume:"60",remaining:"no",noinfo:"no",buffer:"5",checkpolicy:"no",rtl:"no",bg:"e6eef2",text:"333333",leftbg:"d4d4d4",lefticon:"333333",volslider:"666666",voltrack:"FFFFFF",rightbg:"c7c7c7",rightbghover:"999999",righticon:"333333",righticonhover:"FFFFFF",track:"FFFFFF",loader:"009900",border:"CCCCCC",tracker:"DDDDDD",skip:"666666",pagebg:"FFFFFF",transparentpagebg:"yes"});</script>';
    } else {}
    ?>

    Naturally the “###” should be replaced with the page number on which you want this code to appear and the “YOURDOMAIN” needs to be replaced with your specific domain name.

    Also note that this method hard-codes the styling of the player into the header.php file (rather than making it nicely editable through the administration area). Like I said, not an ideal solution – but it works in an emergency.

    Hope this helps someone!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to exclude plugins/scripts from specific pages?’ is closed to new replies.