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

165
Visualizações
How to load external JavaScript in WordPress only for specific folder/subdirectory?

I am trying to load an external JavaScript to execute only in a language version of a website. Example: websitename.com/es/ <-- for Spanish I don't want a custom external (src..) third-party script be loaded onto the whole website. I was trying to use conditional tags in WordPress via functions but there is no option to target all the subdirectory. Using PHP or jQuery. Any solution you can suggest will be appreciated.

EDIT: it's an external script loaded using src, I need it to be applied only to the Spanish version which is in folder '/es/'. I am using polylang.

Thank you in advance

Here is what I was trying to do. I don't know if using taxonomies can help.

function tc_hook_wajs() {   
   if (is_home ('')) { 
        ?>      
      <script type="text/javascript">  
         //js code goes here     
       </script>        <?php      }    } 

   add_action('wp_head', 'tc_hook_wajs');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use the wpml_current_language hook in functions.php to get the current language code and based on languages code you can load each language file separately. here is example :

function my_script() {
 $current_language_code = apply_filters( 'wpml_current_language', null );
 if($current_language_code == 'en') { // English script
    $load_file = 'myscript.js';
 }
 elseif($current_language_code == 'sp') { // Spainsh script
    $load_file = 'myscript-sp.js';
 }
 else { // Italian script
    $load_file = 'myscript-it.js';
 }
 
 wp_enqueue_script( 'custom-js', get_stylesheet_directory_uri() . '/js/'.$load_file, array( 'jquery' ),'',true );
 }
 add_action( 'wp_enqueue_scripts', 'my_script' );
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