Skip to main content

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head() 
{
    global $post;
    if(!empty($post))
    {
        $alternate = get_post_meta($post->ID, 'alternate', true);
        $hreflang = get_post_meta($post->ID, 'hreflang', true);
        if(!empty($alternate) && !empty($hreflang))
        {
            ?>
                <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php>
    }//end of if
  }//end of if  <?php
        }//end 
 of function  }
}

If there is no $alternate and $hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there is no $alternate and $hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head() 
{
    global $post;
    if(!empty($post))
    {
        $alternate = get_post_meta($post->ID, 'alternate', true);
        $hreflang = get_post_meta($post->ID, 'hreflang', true);
        if(!empty($alternate) && !empty($hreflang))
        {
            ?>
                <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" />
            <?php
        } 
    }
}

If there is no $alternate and $hreflang then there would be no link.

Variable names
Source Link
Kumar
  • 2.9k
  • 18
  • 19

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there is no alternate$alternate and hreflang $hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there is no alternate and hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there is no $alternate and $hreflang then there would be no link.

Grammar and punctuation
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there iais no alternate and hreflang hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there ia no alternate and hreflang then there would be no link.

As you said per page/post basis, this would work for each post

add_action('wp_head', 'add_link_in_head');
function add_link_in_head(){
 global $post;
 if(!empty($post)){
    $alternate = get_post_meta($post->ID, 'alternate', true);
    $hreflang = get_post_meta($post->ID, 'hreflang', true);
    if(!empty($alternate) && !empty($hreflang)){?>
       <link rel="alternate" href="<?php echo $alternate; ?>" hreflang="<?php echo $hreflang; ?>" /><?php
    }//end of if
  }//end of if
 }//end of function

If there is no alternate and hreflang then there would be no link.

Source Link
Kumar
  • 2.9k
  • 18
  • 19
Loading