Make WordPress Core


Ignore:
Timestamp:
11/07/2021 11:03:47 PM (3 years ago)
Author:
joedolson
Message:

Widgets: Add filter to disable RSS widget icon.

Add a filter that disables output of the icon on RSS feed widgets. Improves accessibility by providing a path to prevent duplicate or invisible links.

Props sabernhardt, Boniu91.
Fixes #52224.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-rss.php

    r51967 r52031  
    8787        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    8888
    89         $url  = strip_tags( $url );
    90         $icon = includes_url( 'images/rss.png' );
    9189        if ( $title ) {
    92             $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>';
     90            $feed_link = '';
     91            $feed_url  = strip_tags( $url );
     92            $feed_icon = includes_url( 'images/rss.png' );
     93            $feed_link = sprintf(
     94                '<a class="rsswidget rss-widget-feed" href="%1$s"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="%2$s" alt="%3$s"%4$s /></a> ',
     95                esc_url( $feed_url ),
     96                esc_url( $feed_icon ),
     97                esc_attr__( 'RSS' ),
     98                ( wp_lazy_loading_enabled( 'img', 'rss_widget_feed_icon' ) ? ' loading="lazy"' : '' )
     99            );
     100
     101            /**
     102             * Filters the classic RSS widget's feed icon link.
     103             *
     104             * Themes can remove the icon link by using `add_filter( 'rss_widget_feed_link', '__return_false' );`.
     105             *
     106             * @since 5.9.0
     107             *
     108             * @param string $feed_link HTML for link to RSS feed.
     109             * @param array  $instance  Array of settings for the current widget.
     110             */
     111            $feed_link = apply_filters( 'rss_widget_feed_link', $feed_link, $instance );
     112
     113            $title = $feed_link . '<a class="rsswidget rss-widget-title" href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>';
    93114        }
    94115
Note: See TracChangeset for help on using the changeset viewer.