• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Disable Plugins From Loading on Specific Pages – Multiple URLs

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Disable Plugins From Loading on Specific Pages – Multiple URLs

This topic is: not resolved

Tagged: php array

  • This topic has 4 replies, 2 voices, and was last updated 8 years, 4 months ago by Brad Dalton.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • December 21, 2017 at 4:55 am #214715
    netproject
    Participant

    Hello everyone,

    To disable WordPress plugins from loading on specific pages and posts, I'm using a MU-Plugin code suggested on a kinsta.com post (see GitHub below). This way the contact-form-7 plugin, for example, will only be loaded on the contact page.

    Let's say, I want to use a contact form on 2 other pages and disable it on all other pages not using a contact form.

    Being not a developer, I'm struggling with syntax and logic here when trying to add multiple URLs to the code below. I tried to add multiple URLs in two tests, which however resulted in syntax or parse errors.

    Test 1:
    $is_contact_page = strpos( $request_uri, '/contact/', 'contact2', '/contact3' );

    Test 2:
    $is_contact_page = strpos( $request_uri, '/contact/' );
    $is_contact_page = strpos( $request_uri, '/contact2/' );
    $is_contact_page = strpos( $request_uri, '/contact3/' );

    My Question
    Does someone know or can suggest a solution on how to add multiple URLs here? I would like to allow the contact form to be loaded on those defined pages, but disable it on all others.

    Ps: I have tested and installed the Plugin Organizer plugin, but for some websites I'd prefer a programming solution without installing this plugin.

    Code example from Kinsta.com

    <?php
    // returns the path of the request URI without the query string
    // see http://php.net/manual/en/function.parse-url.php
    // and http://php.net/manual/en/reserved.variables.server.php
    // and http://php.net/manual/en/url.constants.php
    
    $request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
     
    $is_admin = strpos( $request_uri, '/wp-admin/' );
    
    // add filter in front pages only
    if( false === $is_admin ){
    	add_filter( 'option_active_plugins', 'kinsta_option_active_plugins' );
    }
    
    /**
     * Filters active plugins
     *
     * @param array   $plugins An array of active plugins.
     */
    function kinsta_option_active_plugins( $plugins ){
    	global $request_uri;
    	$is_contact_page = strpos( $request_uri, '/contact/' );
    
    	$unnecessary_plugins = array();
    
    	// conditions
    	// if this is not contact page
    	// deactivate plugins
    	if( false === $is_contact_page ){
    		$unnecessary_plugins[] = 'contact-form-7/wp-contact-form-7.php';
    		$unnecessary_plugins[] = 'custom-post-type-ui/custom-post-type-ui.php';
    		$unnecessary_plugins[] = 'query-monitor/query-monitor.php';
    	}
    
    	foreach ( $unnecessary_plugins as $plugin ) {
    		$k = array_search( $plugin, $plugins );
    		if( false !== $k ){
    			unset( $plugins[$k] );
    		}
    	}
    
    	return $plugins;
    }

    Resources
    https://kinsta.com/blog/disable-wordpress-plugins/

    Thanks a lot in advance,
    Mark

    December 21, 2017 at 5:40 am #214716
    Brad Dalton
    Participant

    Try using array


    Tutorials for StudioPress Themes.

    December 21, 2017 at 7:47 am #214720
    netproject
    Participant

    Thanks Brad!

    As said, I'm not a developer, so I tried to follow the W3Schools example, and how the array is being used for the multiple plugins within the code example above, but not sure.

    Would the array for the URL sequence look like this?

    function kinsta_option_active_plugins( $plugins ){
    	global $request_uri;
    $is_contact_page = array();
    {
    $is_contact_page = strpos( $request_uri, '/contact/' );
    $is_contact_page = strpos( $request_uri, '/contact1/' );
    $is_contact_page = strpos( $request_uri, '/contact2/' );
    }
    .
    .
    .

    Thanks Mark

    December 31, 2017 at 12:05 pm #214992
    netproject
    Participant

    Just wondering, if anyone has got more ideas on this?

    December 31, 2017 at 9:28 pm #215007
    Brad Dalton
    Participant

    I don't think you need to do this because the code only executes on pages containing the shortcode.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble