Shortcode not working with AJAX WordPress plugin

Problem:

Some one else had the same problem but solution did not work for me

Two: Is your shortcode in your main plugin file. If that code is in another file inside your plugin, did you make sure to include that extra file into your main plugin file]

——I dont know how to do this

Shortcode from plugin is not working, but custom shortcode in functions.php is working.

When putting shortcode in post, it prints text string
[Best_Wordpress_Gallery id=”11″ gal_title=”bc1″]

AJAX.PHP

Ajax.php loads each post by day with the wordpress post loop

get_template_part(‘content’,get_post_format()); ?>

-this will get the correct content.php template file

-for example. “content-video.php” or “content-gallery.php”

query_posts(array( ‘date_query’ => array(array(‘year’ => $year, ‘month’ => $month,’day’ => $day,)),’posts_per_page’=>-1 ));
if (have_posts()) : while (have_posts()) : the_post();

?>

<?php get_template_part(‘content’,get_post_format()); ?>

<?php
endwhile; else:

echo “<p style=’text-align: center; font-size: 15px; padding: 5px;’>Nothing found.</p>”;

endif;

wp_reset_postdata();

die();
}

CONTENT.PHP

This is the template part AJAX.PHP will get
Shortcode from plugin does not work, but a custom shortcode I created in functions.php does work

[Best_Wordpress_Gallery id=”11″ gal_title=”bc1″] it just prints the text and does not execute the shortcode

<?php
$currentissue->posts;
$currentissue->posts[0]->ID;
$id = $currentissue->posts[0]->ID;
$category = get_the_category( $id );

?>

<h3 id=”Post_title”><?php the_title(); ?></h3>

<div class=”<?php echo $category[0]->cat_name; ?>”>
<div class=”embed-responsive embed-responsive-16by9″>

<?php

$content= the_content();

/** @var WP_Embed $wp_embed */
global $wp_embed;

$wp_embed->post_ID = $currentissue->posts[0]->ID;

// first attempt at running shortcode
$wp_embed->run_shortcode( $content );

// plain links on their own line
$wp_embed->autoembed( $content );

// second attempt at running shortcode
echo do_shortcode( $content );

?>
</div>
</div>

FUNCTIONS.PHP

Testing shortcodes, this does work

In the post I have this code [test_shortcodes] and it properly returns ‘Shortcodes are working!’

function test_shortcodes()
{
return ‘Shortcodes are working!’;
}

add_shortcode(‘test_shortcodes’, ‘test_shortcodes’);

Read more here:: Shortcode not working with AJAX WordPress plugin

Leave a Reply

Your email address will not be published. Required fields are marked *