Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Shortcode doesn't work on ajax call in Wordpress

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>';

}

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!