Making WordPress.org


Ignore:
Timestamp:
02/08/2019 03:59:08 AM (6 years ago)
Author:
dd32
Message:

Support Forums: Output <link rel="canonical"> tags for more pages, and correct the topic/forum tag to account for pagination.

Fixes #4073.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r8202 r8215  
    2020        add_action( 'wp_print_footer_scripts',         array( $this, 'replace_quicktags_blockquote_button' ) );
    2121
    22         // Output rel="canonical" meta tag.
    23         add_action( 'wp_head', array( $this, 'rel_canonical' ) );
     22        // Output rel="canonical" meta tag. Runs before WP's rel_canonical to unhook that if needed.
     23        add_action( 'wp_head', array( $this, 'rel_canonical' ), 9 );
    2424
    2525        // Link to create new topics atop topic list.
     
    273273
    274274    /**
    275      * Outputs rel="canonical" for topic tags and views.
     275     * Outputs <link rel="canonical"> tags for various pages.
    276276     */
    277277    public function rel_canonical() {
    278         if ( ! bbp_is_topic_tag() && ! bbp_is_single_view() ) {
    279             return;
    280         }
    281 
     278        $canonical_url = false;
    282279        if ( bbp_is_topic_tag() ) {
    283280            $canonical_url = bbp_get_topic_tag_link();
    284         } else {
     281        } elseif ( bbp_is_single_view() ) {
    285282            $canonical_url = bbp_get_view_url();
     283        } elseif ( bbp_is_forum_archive() ) {
     284            $canonical_url = get_post_type_archive_link( 'forum' );
     285        } elseif ( bbp_is_single_topic() ) {
     286            remove_action( 'wp_head', 'rel_canonical' ); // Doesn't handle pagination.
     287            $canonical_url = bbp_get_topic_permalink();
     288        } elseif ( bbp_is_single_forum() ) {
     289            remove_action( 'wp_head', 'rel_canonical' ); // Doesn't handle pagination.
     290            $canonical_url = bbp_get_forum_permalink();
    286291        }
    287292
    288293        // Make sure canonical has pagination if needed.
    289294        $page = get_query_var( 'paged', 0 );
    290         if ( $page >= 2 ) {
     295        if ( $canonical_url && $page >= 2 ) {
    291296            $canonical_url .= 'page/' . absint( $page ) . '/';
    292297        }
Note: See TracChangeset for help on using the changeset viewer.