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

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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