WP Manifestindependent plugin directory
manifest / developer / should-run-wp

My Custom Plugin

A plugin to demonstrate conditional loading.

by Your Name · github.com/omarhosamcodes/should-run-wp

0stars
1forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/omarhosamcodes/should-run-wp/archive/refs/heads/dev.zip

should-run

This repository demonstrates how to conditionally load a WordPress plugin or code snippet based on the current page. It provides practical examples for enabling or disabling plugin functionality on specific pages using WordPress conditional tags.

Files

  • example.php: A sample WordPress plugin that shows how to prevent direct access and conditionally run code depending on the page.
  • snippit.php: Contains reusable code snippets for conditional plugin loading, including scenarios for excluding or including specific pages.

How It Works

Both files show how to use arrays of page slugs, IDs, or titles to control where your plugin runs:

  • Exclude pages: Run the plugin everywhere except on listed pages.
  • Include pages: Run the plugin only on listed pages.

The logic uses WordPress functions like is_page() and hooks into the wp action for reliable conditional checks.

Usage

  1. Place example.php in your WordPress wp-content/plugins directory and activate it from the admin dashboard.
  2. Edit the $excluded_pages or $included_pages arrays in either file to match your needs.
  3. Use the code in snippit.php to add similar logic to your own plugins or themes.

Requirements

  • WordPress 5.0 or higher
  • PHP 7.0 or higher

License

This project is open source and available under the MIT License.