Title: Conditional activation of wordpress plugin
Last modified: August 20, 2016

---

# Conditional activation of wordpress plugin

 *  [rabinbs](https://wordpress.org/support/users/rabinbs/)
 * (@rabinbs)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/conditional-activation-of-wordpress-plugin/)
 * I want a plugin to work only if it passes a sudden condition and the condition
   is WordPress Post’s Custom Field or its Value. I can get the custom field value
   outside the WordPress Loop() but it is not working when I’m using it on the plugin’s
   page. Here is the code to get the Custom Field Value:
 *     ```
       <?php
           global $wp_query;
           $postID = $wp_query->post->ID;
           $pluginactivate = get_post_meta($postID, 'my-custom-field', true);
           if ($pluginactivate == "yes"){
            echo $pluginactivate;
            //plugin code here
           }
           else {
            echo $pluginactivate;
            //plugin bypassed
           }
           ?>
       ```
   
 * This code is working fine on Single page or Homepage but not working on plugin’s*.
   php page.
 * I found this [topic](http://support.makedesignnotwar.com/discussion/658/activate-on-conditional-field/)
   where Aaron replied what he said is
 * > That wont work, but if you edit the file as follows, it will:
   > Find:
   > public function gallery($content = ”, $attr) {
   >  global $post;
   > Add after:
   > if ( !get_post_meta($post->ID, ‘gallery’, true) ) return;
 * Unfortunately I’m not smart enough to elaborate what he said. Any help will be
   highly appreciated.
    One more thing is this plugin will be triggered only in 
   single post pages like if (is_single())

The topic ‘Conditional activation of wordpress plugin’ is closed to new replies.

 * 0 replies
 * 1 participant
 * Last reply from: [rabinbs](https://wordpress.org/support/users/rabinbs/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/conditional-activation-of-wordpress-plugin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
