Last active
August 29, 2015 14:00
-
-
Save KeSch/11273529 to your computer and use it in GitHub Desktop.
Toolbox-Modul um dem Head-Bereich einen og:image Metatag hinzuzufügen.
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 | |
/* | |
Module Name: Ausgabe der Artikelbilder als og:image Metatag | |
Description: Fügt dem Head-Bereich ein og:image-Metatag mit aktuellem Artikelbild in Vollgröße hinzu. [Frontend] | |
Author: Sergej Müller (edited by Kevin Schludermann) | |
Author URI: http://wpcoder.de | |
*/ | |
/* Sicherheitsabfrage */ | |
if ( ! class_exists('Toolbox') ) { | |
die(); | |
} | |
/* Ab hier kann's los gehen */ | |
function sm_meta_thumb() { | |
/* Keine Feeds und X-Backs */ | |
if ( is_feed() or is_trackback() ) { | |
return; | |
} | |
/* Beiträge mit Thumbs */ | |
if ( is_singular() && has_post_thumbnail() ) { | |
/* Thumbnail in Vollgröße */ | |
$image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); | |
$thumb = $image; | |
/* Default Thumb */ | |
} else { | |
$thumb = 'http://example.com/logo.png'; | |
} | |
/* Ausgabe */ | |
echo sprintf( | |
'%s<meta property="og:image" content="%s" />', | |
"\n", | |
esc_attr($thumb) | |
); | |
} | |
/* Fire */ | |
add_action( | |
'wp_head', | |
'sm_meta_thumb' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment