Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Wordpress: problem to insert a script in a post content

I intend to insert the simple script below in a Wordpress post content through Classic Editor; but whenever I switch to visual mode or publish the post, Wordpress automatically removes the whole code (both HTML tags and script):

<p id="Test"></p>
<script>
var x = 10;
document.getElementById("Test").innerHTML= x;
</script>

To solve the issue, I followed these steps respectively:

1) The following snippet code was added to functions.php- so, now, Wordpress doesn't remove formatted HTML anymore:

function uncoverwp_tiny_mce_fix( $init )
{
    $init['extended_valid_elements'] = 'div[*]';

    return $init;
}
add_filter( 'tiny_mce_before_init', 'uncoverwp_tiny_mce_fix' );

2) By adding the following code, too, the above script is supposed to run on my post (here, for example, post id=123)

function wpb_hook_javascript() {
  if (is_page ('123')) { 
    ?>
        <script type="text/javascript">
          // My javscript code
        </script>
    <?php
  }
}
add_action('wp_head', 'wpb_hook_javascript');

Everything looks fine and logical, but this method doesn't work. I also deferred the script, but the problem remained. What am I missing here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To solve the issue, I installed and activated Advanced Editor Tools plugin; then, from settings, checked the box "Keep paragraph tags in the Classic block and the Classic Editor". so now Wordpress doesn't strip out HTML tags and lets me insert scripts directly in the text editor.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda