Created
August 9, 2017 06:33
-
-
Save metinsaylan/bd8db8a0349b9bf776538e7551271b0b to your computer and use it in GitHub Desktop.
Wordpress meta tags without a plugin
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 | |
/** | |
* @link Escape post content in META Attributes, http://codex.wordpress.org/Data_Validation | |
* @link Complete List of HTML Meta Tags, https://gist.github.com/kevinSuttle/1997924 | |
* @example get_template_part('meta'); | |
*/ | |
?> | |
<meta name="twitter:card" content="summary"> | |
<!--<meta name="twitter:site" content="@YOUR_TWITTER_HANDLE">--> | |
<?php if(is_singular()||is_home()):?> | |
<meta property="og:title" itemprop="name" content="<?php echo is_singular() ? get_the_title() : get_bloginfo('name') ?>"> | |
<meta property="twitter:title" content="<?php echo is_singular() ? get_the_title() : get_bloginfo('name') ?>"> | |
<?php endif ?> | |
<?php if(is_single()||is_home()):?> | |
<meta property="og:description" content="<?php echo is_single() ? get_the_excerpt() : get_bloginfo('description') ?>"> | |
<meta property="twitter:description" content="<?php echo is_single() ? get_the_excerpt() : get_bloginfo('description') ?>"> | |
<meta name="description" itemprop="description" content="<?php echo is_single() ? get_the_excerpt() : get_bloginfo('description') ?>"> | |
<?php endif ?> | |
<?php if(is_singular()||is_home()):?> | |
<meta property="og:url" itemprop="url" content="<?php echo is_singular() ? the_permalink() : bloginfo('wpurl'); ?>"> | |
<meta property="twitter:url" itemprop="url" content="<?php echo is_singular() ? the_permalink() : bloginfo('wpurl'); ?>"> | |
<?php endif ?> | |
<?php if(is_singular()):?> | |
<meta name="revised" content="<?php the_modified_date(DATE_RFC2822); ?>"> | |
<?php endif; ?> | |
<?php | |
if (is_singular()){ | |
if (has_post_thumbnail($post->ID)){ | |
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'large'); | |
$thumb_path = $thumb[0]; | |
echo '<meta property="og:image" itemprop="image" content="'.$thumb_path.'">'; | |
echo '<meta property="twitter:image" itemprop="image" content="'.$thumb_path.'">'; | |
} | |
} ?> | |
<meta property="og:type" content="<?php echo is_singular() ? "article" : "website" ?>"> | |
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"> | |
<?php if(is_singular()):?> | |
<meta name="author" content="<?php the_author_meta('display_name',$post->post_author);?>"> | |
<?php if (get_the_author_meta( 'twitter',$post->post_author )): ?> | |
<meta name="twitter:creator" content="@<?php echo esc_attr(get_the_author_meta('twitter',$post->post_author));?>"> | |
<?php endif; ?> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment