Make Your Own Meta Open Graph Without YOAST

Now, we gonna edit header.php and set some pieces opengraph meta property with wp codex base knowledge. No need YOAST at all.

<meta property="og:title" content="<?php if (is_home()) { bloginfo('name'); } else { the_title(); } ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php if (is_home()) { echo bloginfo('url')."/wp-content/themes/IzulV3LTE/assets/img/og.jpg"; } else { $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(600, 400), false, ''); echo $src[0]; } ?>" />

<meta property="og:url" content="<?php if (is_home()) { bloginfo('url'); } else { the_permalink(); } ?>" />

<meta property="og:description" content="<?php if (have_posts() && is_single() OR is_page()):while(have_posts()):the_post();$out_excerpt = str_replace(array(" \r\n ", "\r ", "\n "), " ", get_the_excerpt());echo apply_filters('the_excerpt_rss', $out_excerpt);endwhile;elseif(is_category() OR is_tag()):if(is_category()):echo "Posts related to Category: ".ucfirst(single_cat_title(" ", FALSE));elseif(is_tag()):echo "Posts related to Tag: ".ucfirst(single_tag_title(" ", FALSE));endif;else: ?>Izulthea`s Blog Made Simple<?php endif; ?>" />

on og:title, if current page is home page, show on og:title blog name. The blog bame mean words you set on Setting > General

on og:image, if current page is home page, show image from your default image. You must have prepared this image on your asset/theme folder, with best dimension 600 x 450 or equal ratio. if current page is single post, call og:image from wp post image/featured image.

on og:url, if current page is home page, just call your blog url, if in single post just call its permalink.

on og:description, if have post and in single post, call excerpt of that post to fill description. If category page, just call single category title and add some words example “Posts related to Category”, if tag page, just call single tag title with some words like “Posts related to Tag”, if home page, just call blog description as you set on Dasgboard > Settings > General

Pretty simple, huh? 😀

Share to

Do You Know!