Making WordPress.org

Changeset 8366


Ignore:
Timestamp:
02/28/2019 05:57:48 AM (6 years ago)
Author:
dd32
Message:

WordPress.TV: Add a canonical link tag to the homepage and taxonomy archives..

Fixes #4208.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/functions.php

    r8230 r8366  
    1818            add_action( 'after_setup_theme', array( $this, 'setup' ) );
    1919        }
     20
     21        // Add any actions/filters that should run for WordPress.TV & Blog.WordPress.TV here.
     22        add_action( 'wp_head', array( $this, 'rel_canonical' ) );
    2023    }
    2124
     
    4144            'featured_wordcamps' => __( 'Featured WordCamps', 'wptv' ),
    4245        ) );
     46    }
     47
     48    /**
     49     * Output `<link rel="canonical">` links where needed.
     50     */
     51    function rel_canonical() {
     52        $canonical = false;
     53
     54        if ( is_front_page() ) {
     55            $canonical = home_url('/');
     56
     57        // Speakers, Events, Producers, Tags, Years/WordCamp.TV,
     58        } elseif ( is_tax() || is_tag() || is_category() ) {
     59            $canonical = get_term_link( get_queried_object() );
     60            if ( is_wp_error( $canonical ) ) {
     61                $canonical = false;
     62            }
     63
     64            if ( $canonical && get_query_var( 'paged' ) > 1 ) {
     65                $canonical .= 'page/' . (int) get_query_var( 'paged' ) . '/';
     66            }
     67        }
     68
     69        if ( $canonical ) {
     70            printf( '<link rel="canonical" href="%s">', esc_url( $canonical ) );
     71        }
    4372    }
    4473
Note: See TracChangeset for help on using the changeset viewer.