• 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 6 years, 1 month ago by vijayj.
    • This topic was modified 6 years, 1 month ago by Jan Dembowski.
Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    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 for when your shortcode callback will run.

    Mike

    (@bigmikey00)

    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.