Created
March 8, 2022 08:28
-
-
Save wpflames/8d950cb1f6e07487b9028114393fe468 to your computer and use it in GitHub Desktop.
Add hreflang attribute to head section
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // ============================================================= | |
| // ADD HREFLANG ATTRIBUTE TO HEAD SECTION | |
| // ============================================================= | |
| function add_hreflang_attr_to_head(){ | |
| $blog_id = get_current_blog_id(); | |
| // ENGLISH | |
| // ======================= | |
| if($blog_id === 1){ | |
| echo '<link rel="alternate" hreflang="en" href="https://YOURWEBSITE.com" />'; | |
| echo '<link rel="alternate" hreflang="x-default" href="https://YOURWEBSITE.com" />'; | |
| } | |
| // HUN | |
| // ======================= | |
| else if($blog_id === 2){ | |
| echo '<link rel="alternate" hreflang="hu" href="https://YOURWEBSITE.com/hu/" />'; | |
| } | |
| // ITALIAN | |
| // ======================= | |
| else if($blog_id === 3){ | |
| echo '<link rel="alternate" hreflang="it" href="https://YOURWEBSITE.com/it/" />'; | |
| } | |
| } | |
| add_action('wp_head', 'add_hreflang_attr_to_head', 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment