• I’m trying to style the rss short code data. Here is the code I included in functions.php. It works and puts the rss links on screen

    //This code is needed to use the wp_rss() function.
    include_once(ABSPATH.WPINC.’/rss.php’);
    function readRss($atts) {
    extract(shortcode_atts(array(
    “feed” => ‘https://’,
    “num” => ‘1’,
    ), $atts));
    return wp_rss($feed, $num);
    }
    add_shortcode(‘rss’, ‘readRss’);

    I’ve tried to style it with this code

    // This code styles short codes
    function caption_shortcode( $atts, $content = null ) {
    return ‘<span class=”caption”>’ . do_shortcode($content) . ‘</span>’;
    }
    add_shortcode(‘caption’, ‘caption_shortcode’);

    If I try to use it in WordPress, however the span is placed after the rss links.

    [caption][rss feed=”https://feeds.nytimes.com/nyt/rss/HomePage&#8221; num=”5″][/caption]

    Does anyone have any ideas?

    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter derekbanas

    (@derekbanas)

    For anyone that has this problem in the future here is the way to fix this problem. Now you’ll be able to use your short code output any where.

    An example can be found here https://www.newthinktank.com/2010/08/post-rss-feeds-in-wordpress/

    //This code is needed to use the wp_rss() function.
    include_once(ABSPATH.WPINC.’/rss.php’);
    function readRss($atts) {
    ob_start();
    extract(shortcode_atts(array(
    “feed” => ‘https://&#8217;,
    “num” => ‘1’,
    ), $atts));
    wp_rss($feed, $num);
    $output_string=ob_get_contents();
    ob_end_clean();
    return $output_string;
    }
    add_shortcode(‘rss’, ‘readRss’);

Viewing 1 replies (of 1 total)
  • The topic ‘How to style short code data’ is closed to new replies.