Guest User

Rank Math PREV & NEXT LANG

a guest
Oct 3rd, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. <?php
  2.  
  3. add_filter('rank_math/frontend/prev_url', 'modify_rank_math_prev_next_links');
  4. add_filter('rank_math/frontend/next_url', 'modify_rank_math_prev_next_links');
  5.  
  6. function modify_rank_math_prev_next_links($link) {
  7. $home_url = home_url();
  8. $weglot = Weglot::Instance();
  9. $idioma_actual = $weglot->currentlang;
  10.  
  11. if ($idioma_actual != 'es' && !empty($link)) {
  12. if (strpos($link, $home_url) === 0) {
  13. $link = str_replace($home_url, '', $link);
  14. }
  15. $link = $home_url . '/' . $idioma_actual . $link;
  16. }
  17.  
  18. return $link;
  19. }
  20.  
  21. add_action('wp_head', function () {
  22. $weglot = Weglot::Instance();
  23. $idioma_actual = $weglot->currentlang;
  24.  
  25. remove_action('wp_head', 'rank_math_frontend_prev_link');
  26. remove_action('wp_head', 'rank_math_frontend_next_link');
  27.  
  28. $prev_link = apply_filters('rank_math/frontend/prev_url', get_previous_posts_page_link());
  29. $next_link = apply_filters('rank_math/frontend/next_url', get_next_posts_page_link());
  30.  
  31. if ($idioma_actual != 'es') {
  32. if ($prev_link) {
  33. echo '<link rel="prev" class="links-imk" href="' . esc_url($prev_link) . '" />' . PHP_EOL;
  34. }
  35.  
  36. if ($next_link) {
  37. echo '<link rel="next" class="links-imk" href="' . esc_url($next_link) . '" />' . PHP_EOL;
  38. }
  39. }
  40. });
Advertisement
Add Comment
Please, Sign In to add comment