Title: Shortcode is not working
Last modified: March 19, 2021

---

# Shortcode is not working

 *  [ashique12009](https://wordpress.org/support/users/ashique12009/)
 * (@ashique12009)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-is-not-working-32/)
 * Hello, my shortcode is not working where the code is in my custom plugin.
 * See the below code:
 *     ```
       <?php
       class Ajax_Activity {
         function __construct() {
           $this->cld_add_custom_shortcode();
         }
         public function cld_add_custom_shortcode(){
           add_shortcode('sc', [$this, 'cld_generate_form']);
         }
         public function cld_generate_form(){
           $form = '
             <form id="green_form" action="">
               field1:<br>
               <input type="text" name="field1" value="">
               <br>
               field2:<br>
               <input type="text" name="field2" value="">
               <br>
               <input type="submit" value="Submit">          
             </form>';
           return $form;
         }
       }
       ```
   
 * **Note:** add_shortcode line is in a inner php file in my custom plugin.
    _I 
   include this class by below way:_
 *     ```
       <?php 
       class Admin_Classes_Loader {
         function __construct() {
           require_once CA_FEEDER_DIR_PATH . '/admin/Ajax_Activity.php';
           new Ajax_Activity(); 
         }
       }
       ```
   
 * And this class loader is invoked in main plugin file.
    -  This topic was modified 5 years, 2 months ago by [ashique12009](https://wordpress.org/support/users/ashique12009/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-is-not-working-32/#post-14205895)
 * To be honest, manually reviewing I can’t see anything obvious.
 * So I would at this stage revert to xdebug set some break points and see that 
   everything is actually getting called.
 * Not sure if you care, but WP has it own coding standards, whilst there is no 
   compulsion to use them in plugins ( private or public ) many of them make sense
   
   1. class file names Ajax_Activity class file would be class-ajax-activity.php
   one reason is not all file systems are good with upper / lower cases and underscores
   2. WP coding standards prefer array() rather than [] for readability – it is 
   useful to add codesniffer / WP coding standards to your IDE if you are interested
    -  This reply was modified 5 years, 2 months ago by [Alan Fuller](https://wordpress.org/support/users/alanfuller/).
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-is-not-working-32/#post-14208181)
 * The Ajax_Activity class works fine on my site. I didn’t bother breaking the classes
   into separate files since our file systems differ anyway. Do you have WP_DEBUG
   defined as true? Or did you check the error log for clues? If you’re sure Ajax_Activity
   is properly instantiating, maybe the issue is where you placed the actual “[sc]”
   on the page. Some content on a page isn’t filtered through `do_shortcode()`, 
   as might be the case with certain widget content. When that’s the case “[sc]”
   would appear as plaintext.
 *  Thread Starter [ashique12009](https://wordpress.org/support/users/ashique12009/)
 * (@ashique12009)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-is-not-working-32/#post-14209973)
 * Thanks I got the issue, I made a condition is_admin to shortcode class instantiation.
   
   That is why my shortcode was not working.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcode is not working’ is closed to new replies.

## Tags

 * [custom plugin](https://wordpress.org/support/topic-tag/custom-plugin/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 3 replies
 * 3 participants
 * Last reply from: [ashique12009](https://wordpress.org/support/users/ashique12009/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/shortcode-is-not-working-32/#post-14209973)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
