Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
Created July 6, 2012 14:25
Show Gist options
  • Select an option

  • Save alexkingorg/3060451 to your computer and use it in GitHub Desktop.

Select an option

Save alexkingorg/3060451 to your computer and use it in GitHub Desktop.
Conditional loading of a plugin within a WordPress theme.
<?php
// Run this code on 'after_theme_setup', when plugins have already been loaded.
add_action('after_setup_theme', 'my_load_plugin');
// This function loads the plugin.
function my_load_plugin() {
// Check to see if your plugin has already been loaded. This can be done in several
// ways - here are a few examples:
//
// Check for a class:
// if (!class_exists('MyPluginClass')) {
//
// Check for a function:
// if (!function_exists('my_plugin_function_name')) {
//
// Check for a constant:
// if (!defined('MY_PLUGIN_CONSTANT')) {
if (!class_exists('Social')) {
// load Social if not already loaded
include_once(TEMPLATEPATH.'plugins/my-plugin/my-plugin.php');
}
}
@Pushplaybang
Copy link
Copy Markdown

nice one. and a very helpful post too explaining how wordpress loads.

@danyj
Copy link
Copy Markdown

danyj commented May 17, 2015

thnx bud! excellent addon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment