Title: Error in displaying shortcode content
Last modified: January 9, 2019

---

# Error in displaying shortcode content

 *  [vijayj](https://wordpress.org/support/users/vijayj/)
 * (@vijayj)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/error-in-displaying-shortcode-content/)
 * I am creating a custom plugin for adding news feeds to my website.Using a short
   code for adding the feeds to a specific page.But the feeds are displaying in 
   all the pages.can someone please help
 *     ```
            function Feed_Details(){   
   
           global $wpdb;
       	 $table_name  = $wpdb->prefix."skoop_category";
       $category_db = $wpdb->get_results( 
       	"
       	SELECT *
       	FROM $table_name 
       	WHERE id=1
       	"
       );
   
       foreach ( $category_db as $category_db_value ) 
       {
       $category_name= $category_db_value->category;
       }
          	   $url = site_url();
       	    $service_url = "My API Call";
       		$url2="&&url=";
       		$result = sprintf("%s%s%s%s",$service_url,$category_name,$url2,$url);
       		echo($result );
       $curl = curl_init($result);
       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       $curl_response = curl_exec($curl);
       if(!$curl_response || strlen(trim($curl_response)) == 0)
       {
       	?>
          <h1> Sorry No Content to Show </h1>
          <?php
       }else{
       $decoded = json_decode($curl_response,TRUE);
       $numOfCols = 4;
       $rowCount = 0;
       $bootstrapColWidth = 12 / $numOfCols;
       ?>
       <div class="row">
       <?php
       if(empty($decoded)){
       		?> 
       		<div class="no-data"
       		 <h4>        No Data available in this Category </h4>
       		 </div
       		<?php
       	}else{
       foreach ($decoded as $key =>$value) {
       	$data=get_data($value);
       ?>  
               <div class="col-md-<?php echo $bootstrapColWidth; ?>">
                   <div class="thumbnail">
       				<img />">
       				<a>">
       				<?php echo $data[2]; ?></a>
       				<p><?php echo $data[3]; ?> </p>
                </div>
               </div>
       <?php
           $rowCount++;
           if($rowCount % $numOfCols == 0) echo '</div><div class="row">';					
       }
        }
       ?>
       </div>
       <?php
          }
          }
       add_shortcode('feed_details', 'Feed_Details');
           add_action( 'the_content', 'Feed_Details' );
       add_action('admin_menu', 'Skoop');
          ?>
       ```
   
    -  This topic was modified 7 years, 3 months ago by [vijayj](https://wordpress.org/support/users/vijayj/).
    -  This topic was modified 7 years, 3 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

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

 *  [Howdy_McGee](https://wordpress.org/support/users/howdy_mcgee/)
 * (@howdy_mcgee)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/error-in-displaying-shortcode-content/#post-11069361)
 * You’re calling your shortcode code using `the_content` action hook which is going
   to run any and every time `the_content()` function is used, which is often a 
   lot. You should review the [Shortcode API Documentation](https://codex.wordpress.org/Shortcode_API).
 * You can add the shortcode, then in the traditional WordPress editor you can use`[
   Feed_Details]` in the content editor which will call your shortcode. If you’re
   trying to inject the shortcode into the content without giving the user a choice
   you need to [add conditionals](https://codex.wordpress.org/Conditional_Tags) 
   for when your shortcode callback will run.
 *  [Mike](https://wordpress.org/support/users/bigmikey00/)
 * (@bigmikey00)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/error-in-displaying-shortcode-content/#post-11070488)
 * at the end of your code you have
 * `add_action( 'the_content', 'Feed_Details' );`
    Just remove this line and you
   will be fine. Not sure why the guy above did not explain a little better.
 * This code here is going to run every time you load any page period. Which will
   more likely cause a memory issue. To stop that just remove this line.
 * If you wrote this code im pretty sure you know how to put [feed_details] in the
   editor for that page. dont use [Feed_Details] as that is incorrect.

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

The topic ‘Error in displaying shortcode content’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 2 replies
 * 3 participants
 * Last reply from: [Mike](https://wordpress.org/support/users/bigmikey00/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/error-in-displaying-shortcode-content/#post-11070488)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
