Last active
November 5, 2019 20:52
-
-
Save ginsterbusch/a63b219be9d793af4d7c807422942127 to your computer and use it in GitHub Desktop.
RSS Feed embedding using shortcode(s). Implemented as function instead of class, both for easier copy + paste into the functions.php file of your current (child) theme, and also quicker understanding whats going on :) #wordpress #classicpress
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 | |
/** | |
* RSS Feed embedding using shortcode(s). Implemented as function instead of class, both for easier copy + paste into the functions.php file of your current (child) theme, and also quicker understanding whats going on :) | |
* Normally, this would be implemented as a class with a nifty auto-loader / auto-shortcode registration. | |
* | |
* @author Fabian Wolf (@link https://wp-devil.de/) | |
*/ | |
if( !function_exists( 'wp_rss' ) ) { | |
include_once( ABSPATH . WPINC . '/rss.php' ); | |
} | |
if( !function_exists( '__rss_feed_shortcode' ) ) { | |
function __rss_feed_shortcode( $attr = array(), $content = '' ) { | |
$return = ''; | |
$default_attr = array( | |
'url' => '', | |
'feed' => '', // alias for 'url' | |
'limit' => 5, | |
); | |
extract( shortcode_atts( $default_attr, $attr ), EXTR_SKIP ); | |
if( !empty( $url ) ) { | |
if( empty( $limit ) ) { | |
$limit = -1; | |
} else { | |
$limit = intval( $limit ); | |
} | |
// additional safety | |
if( function_exists( 'wp_rss' ) ) { | |
$html_rss = wp_rss( $url, $limit ); | |
} | |
if( !empty( $html_rss ) ) { | |
$return = $html_rss; | |
} | |
} | |
return $return; | |
} | |
} | |
if( function_exists( '__rss_feed_shortcode' ) ) { | |
add_shortcode( 'rss_feed', '__rss_feed_shortcode' ); | |
} | |
// closing tag intentionally left out ;-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment