1

I'm looking to remove the link and icon from rss feed widget. Is there a way it can be done? Obviously I don't want to modify the core files.

So desired output is:

<h3 class="widget-title">RSS Title</h3>

Instead of the default:

<h3 class="widget-title">
<a href="http://www.example.com/url/feed/" class="rsswidget">
    <img height="14" width="14" alt="RSS" src="http://example.com/wp-includes/images/rss.png" style="border:0" class="rss-widget-icon"></a> <a href="http://www.example.com/" class="rsswidget">RSS Title</a>

I know that there is widget_title filter, but I can't get it to work.

Code examples would be appreciated.

More Details

So there is this code in /wp-includes/widgets/class-wp-widget-rss.php

/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );

        $url = strip_tags( $url );
        $icon = includes_url( 'images/rss.png' );
        if ( $title )
            $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">'. esc_html( $title ) . '</a>';

        echo $args['before_widget'];
        if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        }
        wp_widget_rss_output( $rss, $instance );
        echo $args['after_widget'];

        if ( ! is_wp_error($rss) )
            $rss->__destruct();
        unset($rss);

And I see that there is a filter there, but I'm not sure how to use it to remove the link and the icon.

  • can we see your code with the filter approach? so far you got no code at all. – iantsch Mar 18 '16 at 19:05
  • don't really have code to show. Just not sure how to do it. – Ross Mar 18 '16 at 19:29
2

You are trying to modify a built-in widget. Unfortunately for you there is no easy solution to get the results you desire. As you figured out already, there is no filter hook to modify the whole title output.

How to get the results?

  1. Create your own Widget extending WP_Widget_RSS where you overwrite the parents method widget with your designated method. Then replace the build-in version with yours.

    Some help to get you started:

    class WP_Widget_RSS_Custom extend WP_Widget_RSS {
        public function widget($args, $instance) {
            // Copy parent function and modify to your needs…
        }
    }
    
    add_action('widgets_init', 'widget_WP_Widget_RSS_Custom_init');
    
    function widget_WP_Widget_RSS_Custom_init() {
        unregister_widget('WP_Widget_RSS');
        register_widget('WP_Widget_RSS_Custom');
    }
    
  2. Create a JS based solution, that modifies the widget after DOM is ready.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.