Making WordPress.org

Changeset 9572


Ignore:
Timestamp:
03/06/2020 09:42:03 PM (4 years ago)
Author:
coffee2code
Message:

Showcase: Disable comment feeds.

Props jonoaldersonwp, coffee2code.
Fixes #5069.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-showcase/functions.php

    r9069 r9572  
    11<?php
    22
     3// Add support for adding feed links to head.
    34add_theme_support( 'automatic-feed-links' );
     5
     6// Disable comments feed.
     7add_filter( 'feed_links_show_comments_feed', '__return_false' );
     8
     9// Remove extra feed links from singular queries.
     10add_action( 'wp_head', function () {
     11    if ( is_singular() ) {
     12        remove_action( 'wp_head', 'feed_links_extra', 3 );
     13    }
     14}, 1 );
    415
    516function get_site_domain( $rep_slash = true, $echo = true, $rem_trail_slash = false ) {
     
    205216
    206217function extras_feed( $is_comments_feed = false ) {
     218    // Don't do anything for comment feeds.
    207219    if ( $is_comments_feed ) {
    208         do_feed_rss2( $is_comments_feed ); // Load default for comments
    209220        return;
    210221    }
     
    283294    return "&#124;";
    284295} );
     296
     297// Potentially change behavior prior to fetching posts.
     298add_action( 'pre_get_posts', function( $query ) {
     299    // Redirect comment feeds to associated post.
     300    if ( $query->is_comment_feed() ) {
     301        wp_safe_redirect( home_url( $query->query_vars['name'] ) );
     302        return;
     303    }
     304} );
     305
Note: See TracChangeset for help on using the changeset viewer.