Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Pushplaybang Pushplaybang commented Jan 20, 2013

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

@danyj

This comment has been minimized.

Copy link

@danyj 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