Last active
August 29, 2015 13:57
-
-
Save vdite/9803385 to your computer and use it in GitHub Desktop.
Manual Twitter Cards and OG Graph Integration in Wordpress Head.php
This file contains 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 if ( is_singular() || is_front_page() ) { ?> | |
<meta name="twitter:card" content="summary" /> | |
<meta name="twitter:creator" content="@YOUR-TWITTER-NAME" /> | |
<meta name="twitter:url" content="<?php the_permalink() ?>" /> | |
<meta name="twitter:title" content="<?php do_action('wpseo_the_title') ?>" /> | |
<meta name="twitter:description" content="<?php do_action('wpseo_the_desc') ?>" /> | |
<meta property="og:title" content="<?php do_action('wpseo_the_title') ?>"> | |
<meta property="og:type" content="article"> | |
<meta property="og:url" content="<?php the_permalink() ?>"> | |
<meta property="og:description" content="<?php do_action('wpseo_the_desc') ?>"> | |
<?php if ( is_singular() && has_post_thumbnail(get_the_ID()) ) { | |
$post_thumbs = wp_get_attachment_image_src( | |
get_post_thumbnail_id( get_the_ID() ), | |
'full' | |
); | |
if ( ! empty($post_thumbs[0]) ) { ?> | |
<meta name="twitter:image" content="<?php echo esc_url($post_thumbs[0]) ?>" /> | |
<link rel="image_src" href="<?php echo esc_url($post_thumbs[0]) ?>"> | |
<meta property="og:image" content="<?php echo esc_url($post_thumbs[0]) ?>"> | |
<?php } | |
} ?> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for do_action('wpseo_the_title') and do_action('wpseo_the_desc') you 'll need wpseo plugin installed