Skip to content

Instantly share code, notes, and snippets.

@KeSch
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeSch/11273529 to your computer and use it in GitHub Desktop.
Save KeSch/11273529 to your computer and use it in GitHub Desktop.
Toolbox-Modul um dem Head-Bereich einen og:image Metatag hinzuzufügen.
<?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