Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda