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

199
Vistas
Activar la función Js al hacer clic

Estoy usando wordpress y tengo una función como esta, cómo redirigir a la URL correspondiente solo ocurre al hacer clic, por ahora, la página de idioma "en" se redirige automáticamente después de cargar la página, pero el redireccionamiento "zh-hant" después de hacer clic, cualquiera ¿Puede ayudarme a verificar el código? Gracias.

 add_action( 'wp_head', 'redirect_after_booking' ); function redirect_after_booking() { if ( in_category('teachers') ) { if(ICL_LANGUAGE_CODE=='en'){ ?> <script> window.beforeConfirmedBooking = function() { window.location.href = "https://aaa.com"; }; </script> <?php } if(ICL_LANGUAGE_CODE=='zh-hant'){ ?> <script> window.beforeConfirmedBooking = function() { window.location.href = "https://aaa.com/zh-hant"; }; </script> <?php } } }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Deberías hacerlo todo en una sola función.

 add_action( 'wp_head', 'redirect_after_booking' ); function redirect_after_booking() { if ( in_category('teachers') ) { $url_endpoint = ''; if(ICL_LANGUAGE_CODE=='en'){ } else if (ICL_LANGUAGE_CODE=='zh-hans') { $url_endpoint = '/zh-hans'; }else if (ICL_LANGUAGE_CODE=='zh-hant') { $url_endpoint = '/zh-hant'; } ?> <script> window.beforeConfirmedBooking = function() { window.location.href = "https://aaa.com<?php echo $url_endpoint; ?>"; }; const btn = document.querySelector('.el-button .el-button--primary .redirect-link'); btn.addEventListener('click', beforeConfirmedBooking); </script> <?php } }

También puede hacerlo simplemente usando php y sin js en absoluto

 add_action( 'wp_head', 'redirect_after_booking' ); function redirect_after_booking() { if ( in_category('teachers') ) { $url_endpoint = ''; if(ICL_LANGUAGE_CODE=='en'){ } else if (ICL_LANGUAGE_CODE=='zh-hans') { $url_endpoint = '/zh-hans'; }else if (ICL_LANGUAGE_CODE=='zh-hant') { $url_endpoint = '/zh-hant'; } } } // The following will redirect you to where ever you want header('Location: https://aaa.com' . $url_endpoint); /* Make sure that code below does not get executed when we redirect. */
about 4 years ago · Juan Pablo Isaza Denunciar

0

Un método sería hacer lo siguiente usando una declaración de cambio.

Esto permite un fácil crecimiento y, en caso de que termine con MUCHOS idiomas, es fácil repetirlos y recurre a la URL del sitio en caso de que no haya una coincidencia.

 add_action( 'wp_head', 'redirect_after_booking' ); function redirect_after_booking() { if ( in_category('teachers') ) { switch (CL_LANGUAGE_CODE) { case 'zh-hant': wp_redirect( trailingslashit( get_site_url() ) . CL_LANGUAGE_CODE ); exit; break; default: wp_redirect( get_site_url() ); exit; } } }
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