Skip to content

Instantly share code, notes, and snippets.

@vdite
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdite/9803385 to your computer and use it in GitHub Desktop.
Save vdite/9803385 to your computer and use it in GitHub Desktop.
Manual Twitter Cards and OG Graph Integration in Wordpress Head.php
<?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 } ?>
@vdite
Copy link
Author

vdite commented Mar 30, 2014

  • put this before tag in your head.php

for do_action('wpseo_the_title') and do_action('wpseo_the_desc') you 'll need wpseo plugin installed

@vdite
Copy link
Author

vdite commented Mar 30, 2014

pls visit me @ http://mizine.de

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment