0
votes

I have a website on WordPress (Im still new to WordPress) and in it I created a Blog-Page. I made the blog page with custom PHP code however, now I wanna add some custom <meta> tags for social media sharing such as Facebook or Twitter etc.

However in my document it only has the body and an WordPress anchor

/* 
* Template Name: news-article 
* Template Post Type: page 
*/ 
get_header(); 

so if i put it on the blog-page then it wont work because it is only the body and <meta> don't work in body. If i go to the header then it is general header function that will be on every page on the WordPress website.

So Do I put it in the general Header and just like have a conditional statement so it doesn't run on every page other than the blog pages, or is there a way in WordPress to do this?
Thank you in advance

EDIT

<!-- for blog pages -->
    <?php
    if ( is_home() ) {
        echo '<meta name="description" content="' . $rs_news_rows['nsubheading'] . '">
        <meta property="og:title" content="' . $rs_news_rows['nheadline'] .'">
        <meta property="og:description" content="'. $rs_news_rows['nsubheading'].'">'
 }
    ?>
1

1 Answers

0
votes

you may use this PHP code in your template

if ( is_front_page() && is_home() ) {
  // Default homepage
} elseif ( is_front_page() ) {
  // static homepage
} elseif ( is_home() ) {
  // blog page
} else {
  //everyting else
}

Or simply

if ( is_home() ) {
  // blog page
}