I have big problem with loading ajax content in Wordpress. Ajax loading works but inside loaded file is shortcode which is show as plain text. I tried many many solutions that supposed to work but none of it works... My code is:
echo do_shortcode( apply_filters( 'the_content', $post->post_content ) );
But even if I hard code shortcode it still show as plain text. Actually I use Content no cache plugin but I tried different things and result is the same. I need to execute this shortcode. I need to use ajax to avoid cache. Any ideas?
This is my whole code for now:
add_action( 'wp_ajax_showBanner', 'showBanner' );
add_action( 'wp_ajax_nopriv_showBanner', 'showBanner' );
function showBanner() {
echo do_shortcode( '[adrotate group="1"]' );
wp_die();
}
function getBanner() {
echo '<div class="adr"></div>
<script>
window.addEventListener( "load", function() {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "' . admin_url( 'admin-ajax.php' ) . '", true);
xhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded;");
xhttp.onload = function () {
if (this.status >= 200 && this.status < 400) {
document.querySelector( ".adr" ).innerHTML = this.responseText;
} else {
document.querySelector( ".adr" ).innerHTML = "Error";
}
};
xhttp.send("action=showBanner");
});
</script>';
}