My Custom Plugin
A plugin to demonstrate conditional loading.
★ 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.zipshould-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
- Place
example.phpin your WordPresswp-content/pluginsdirectory and activate it from the admin dashboard. - Edit the
$excluded_pagesor$included_pagesarrays in either file to match your needs. - Use the code in
snippit.phpto 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.