Opened 3 months ago
Last modified 7 weeks ago
#23692 new enhancement
feed_links should have a parameter to choose which feed to display
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Feeds | Version: | |
| Severity: | minor | Keywords: | dev-feedback needs-patch |
| Cc: | juliobosk@… |
Description
Hello,
feed_links is a function located in wp_includes/general_template.php. It displays 2 feeds in the header : the main feed and the comment feed. The function is activated along with feed_links_extra when automatic-feed-links support is activated.
Currently, developers can't choose if they want both feeds to be displayed, or just one of them. I think this function should be improved.
Here is the current function :
function feed_links( $args = array() ) {
if ( !current_theme_supports('automatic-feed-links') )
return;
$defaults = array(
/* translators: Separator between blog name and feed type in feed links */
'separator' => _x('»', 'feed link'),
/* translators: 1: blog title, 2: separator (raquo) */
'feedtitle' => __('%1$s %2$s Feed'),
/* translators: %s: blog title, 2: separator (raquo) */
'comstitle' => __('%1$s %2$s Comments Feed'),
);
$args = wp_parse_args( $args, $defaults );
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
}
Currently, the only way to display only one feed (the main post feed or the main comment feed) so is to deactivate feed_links with :
remove_action('wp_head', 'feed_links', 2);
and then to create our own function to only display one feed.
Do you think this should be improved ?
Regards,
Change History (8)
I think it could be improved this way :
// Default : add_theme_support( 'automatic-feed-links'); // only main feed add_theme_support( 'automatic-feed-links', true, false ); // only comment feed add_theme_support( 'automatic-feed-links', false, true); // new url for main feed add_theme_support( 'automatic-feed-links', 'http://website.com/new-feed-url', true); // new url for comment feed add_theme_support( 'automatic-feed-links', true, 'http://website.com/new-feed-url');
What do you think ?
Hello i propose a simple filter :
function feed_links( $args = array() ) {
if ( !current_theme_supports('automatic-feed-links') )
return;
$defaults = array(
/* translators: Separator between blog name and feed type in feed links */
'separator' => _x('»', 'feed link'),
/* translators: 1: blog title, 2: separator (raquo) */
'feedtitle' => __('%1$s %2$s Feed'),
/* translators: %s: blog title, 2: separator (raquo) */
'comstitle' => __('%1$s %2$s Comments Feed'),
);
$args = wp_parse_args( $args, $defaults );
$feed_and_coms = apply_filters( 'feed_links_types', 3 ); // 1 = feed, 2 = coms, 3 = both
if( $feed_and_coms==1 || $feed_and_coms==3 )
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
if( $feed_and_coms==2 || $feed_and_coms==3 )
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
}
To show only feed :
add_filter( 'feed_links_types', 'baw_show_only_feed' );
function baw_show_only_feed(){
return 1;
}
To show only coms :
add_filter( 'feed_links_types', 'baw_show_only_coms' );
function baw_show_only_feed(){
return 2;
}
To show both, do nothing ;)
comment:6
follow-up:
↓ 7
SergeyBiryukov — 2 months ago
The filter makes sense, however the values to check should be actual words (I'd suggest 'posts', 'comments', and 'all'), rather than numbers.
Replying to SergeyBiryukov:
The filter makes sense, however the values to check should be actual words (I'd suggest 'posts', 'comments', and 'all'), rather than numbers.
Or it should filter an actual array of arguments, so one could set 'comments' => false. Or each feed can have its own filter.

to improve: