Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!