Announcement
Collapse
No announcement yet.
Wordpress hreflang tags in head section on certain posts only
Collapse
X
-
Thanks Leslie. Off hand not seeing any that will just display the Spanish hreflang on those Spanish posts and not display it on any non-spanish.
-
Hi Jamie, as David mentioned, if this is a child theme function.php you could try it there but keep in mind even though it's its own file there might be an occasional update down the road that could still break it. Have you looked to see if there are any WordPress plug-in's that might do this for you?Originally posted by jsdva View PostSite owner has a Wordpress blog in English and a translation service for Spanish; however, to keep costs down, the posts with high traffic are being translated to Spanish manually and will be cut from the translation service. So each of those high-traffic posts have an English and Spanish version. So, we want to add an hreflang to the function.php, But, only for those pages we are manually translating. Hope this makes sense.
Found the below, the only thing is it is going to get rather large as we add more and more of the high-traffic post. So, kind of two-fold question:
1. Will the function below work? If not, can you help me adjust it to work?
2. What happens as more and more blog ids are added to this function. Will performance be affected?
Just thought I'd give the forum a whirl, in the event anyone has dealt with something like this before.PHP Code:function add_hreflang_tags() { if (is_front_page() || is_home()) { echo '<link rel="alternate" hreflang="es" href="https://es.example.com/blog" />'; } if (is_single('1234')) { echo '<link rel="alternate" hreflang="en-es" href="https://es.example.com/blog/" />'; } } add_action('wp_head', 'add_hreflang_tags');
Thanks in advance for any advice,
Jamie
Leave a comment:
-
I would highly recommend not altering a core Wordpress file. Any update that replaces the file will break the change, and no copy of Wordpress should be left not updated. Assuming the goal is not possible with a trustworthy plugin, or in the software somewhere, then customization should be handled via a child theme so the primary files can continue receiving updates and only the child theme file contains a custom function.
Leave a comment:
-
Wordpress hreflang tags in head section on certain posts only
Site owner has a Wordpress blog in English and a translation service for Spanish; however, to keep costs down, the posts with high traffic are being translated to Spanish manually and will be cut from the translation service. So each of those high-traffic posts have an English and Spanish version. So, we want to add an hreflang to the function.php, But, only for those pages we are manually translating. Hope this makes sense.
Found the below, the only thing is it is going to get rather large as we add more and more of the high-traffic post. So, kind of two-fold question:
1. Will the function below work? If not, can you help me adjust it to work?
2. What happens as more and more blog ids are added to this function. Will performance be affected?
Just thought I'd give the forum a whirl, in the event anyone has dealt with something like this before.PHP Code:function add_hreflang_tags() { if (is_front_page() || is_home()) { echo '<link rel="alternate" hreflang="es" href="https://es.example.com/blog" />'; } if (is_single('1234')) { echo '<link rel="alternate" hreflang="en-es" href="https://es.example.com/blog/" />'; } } add_action('wp_head', 'add_hreflang_tags');
Thanks in advance for any advice,
Jamie
Tags: None
Leave a comment: