Snippets

Joseph Dickson OpenGraph

Created by Joseph Dickson
// Assign opengraph varables for Archives and Posts
if ( is_archive() ) {
	if ( has_custom_logo() ) {
		$custom_logo_id = get_theme_mod( 'custom_logo' );
		$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
		$image = $image[0];
	}

	$permalink = get_post_type_archive_link( 'post' );
	$title = 'Archive'; 

} else {

	if (has_post_thumbnail() ) {
		$image = get_the_post_thumbnail_url();
	} else {
		$custom_logo_id = get_theme_mod( 'custom_logo' );
		$image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
		$image = $image[0];
	}

	$permalink = get_permalink();
	$title = get_the_title();

}

	echo '<meta property="og:title" content="' . $title . '" />';
	echo '<meta property="og:type" content="website" />';
	echo '<meta property="og:url" content="' . $permalink . '" />';
	echo '<meta property="og:image" content="' . $image . '" />';

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.