Last active
November 11, 2016 02:47
-
-
Save megaxorg/6d067adb9bc9037f1a75 to your computer and use it in GitHub Desktop.
Display images from your post in the RSS Feed. Checks for featured images and images in the post content.
This file contains hidden or 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 | |
/* | |
Plugin Name: sxss Featured Image Feed | |
Plugin URI: http://sxss.nw.am | |
Description: Display the featured image in the RSS feed | |
Version: 0.2 | |
Author: sxss | |
*/ | |
function sxss_featured_images_in_rss( $content ) { | |
// Post Objekt verfügbar machen | |
global $post; | |
// Wenn ein WP-Artikelbild vorhanden ist | |
if ( has_post_thumbnail( $post->ID ) ){ | |
// Erst Artikelbild, dann Inhalt ausgeben | |
return get_the_post_thumbnail( $post->ID ) . $content; | |
} | |
// Content auf Bilder durchsuchen | |
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post->post_content, $matches ); | |
// Wenn Bilder gefunden wurden Bild + Content zurückgfeben | |
if ( isset( $matches ) && !empty( $matches[1][0] ) ) | |
return '<img src="' . $matches[1][0] . '">' . $content; | |
// Wenn kein Bild gefunden wurde Content zurückgeben | |
return $content; | |
} | |
add_filter( 'the_excerpt_rss', 'sxss_featured_images_in_rss' ); | |
add_filter( 'the_content_feed', 'sxss_featured_images_in_rss' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment