How to add custom PHP code in post header?

admin2025-06-06  1

In header.php i want to add :

1. For home page :

link rel="alternate" href="/fr/" hreflang="fr-FR"

2. For custom single post :

link rel="alternate" href="/fr/category/post-name/" hreflang="fr-FR"

What code will be use for this ?

In header.php i want to add :

1. For home page :

link rel="alternate" href="/fr/" hreflang="fr-FR"

2. For custom single post :

link rel="alternate" href="/fr/category/post-name/" hreflang="fr-FR"

What code will be use for this ?

Share Improve this question edited Nov 1, 2018 at 11:45 Pratik Patel 1,1091 gold badge11 silver badges23 bronze badges asked Nov 1, 2018 at 7:34 Sunny K. UjjawalSunny K. Ujjawal 12 bronze badges 1
  • See here wordpress has some conditional tag that will help you to do what you want codex.wordpress/Conditional_Tags – mlimon Commented Nov 1, 2018 at 7:43
Add a comment  | 

1 Answer 1

Reset to default 0

Please try like

if ( is_front_page() || is_home() ) {
    //IF HOME PAGE
}

if ( is_singular('YOUR-CUSTOM-POST-TYPE-HERE') ) {
  // FOR SINGLE PAGE STUFF
}

Please make sure you have to replace YOUR-CUSTOM-POST-TYPE-HERE with your Custom post type.

Please let me know if any query.

Thanks!

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749214609a317323.html

最新回复(0)