Reputation: 65
I am developing a wordpress plugin for event slider , but when i add shortcode to display the slider the wordpress page editor doesnot update and it is also rendering the content in admin dashboard.
the error i am getting is "Updating failed. Error message: The response is not a valid JSON response."
screenshot of updating failed error
event-plugin.php file
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
include PLUGIN_DIR_PATH.'views/shortcode-template.php';
}
shortcode-template.php
<?php
$allevents=display_events_from_db();
?>
<div class="main-eps">
<?php
if (count($allevents)>0){
foreach($allevents as $key=>$value){
?>
<div class="eps-event-cards">
<div class="img-cont">
<img src="<?php echo $value['thumb'] ?>" class="event-thumb">
</div>
<div class="textcont">
<a href="<?php echo $value['slug']; ?>"><p class="event-title"><?php echo $value['title'] ?></p></a>
<p class="event-desc">
<?php
$aa=$value['description'];
if (strlen($aa) >= 40) {
echo substr($aa, 0, 40)." ... ";
}
else {
echo $aa;
}
?>
</p>
<p class="event-date">
<?php
$newDate = date("l M, d, Y", strtotime($value['date']));
echo $newDate;
?>
</p>
</div>
</div>
<?php
}
}
?>
</div>
Upvotes: 5
Views: 1654
Reputation: 4412
You forget add return
:
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
return include PLUGIN_DIR_PATH.'views/shortcode-template.php';
}
Hope help you.
Upvotes: 0
Reputation: 21681
Change your shortcode to
add_shortcode("myeventplugin","short_code_view");
function short_code_view(){
ob_start();
include PLUGIN_DIR_PATH.'views/shortcode-template.php';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
Upvotes: 7