Forums

How to style short code data (2 posts)

  1. derekbanas
    Member
    Posted 1 year ago #

    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" => 'http://',
    "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="http://feeds.nytimes.com/nyt/rss/HomePage" num="5"][/caption]

    Does anyone have any ideas?

    Thanks

  2. derekbanas
    Member
    Posted 1 year ago #

    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 http://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" => 'http://',
    "num" => '1',
    ), $atts));
    wp_rss($feed, $num);
    $output_string=ob_get_contents();
    ob_end_clean();
    return $output_string;
    }
    add_shortcode('rss', 'readRss');

Topic Closed

This topic has been closed to new replies.

About this Topic