/** * Single canonical for the site (owner 2026-11-09, docs/SEARCH-CONSOLE-INDEXING-AUDIT-2026-11-09.md). * * Printed only by add_comprehensive_seo_tags(). WordPress core rel_canonical is removed so there is never a second * tag. Pages with their own SEO head keep theirs: Investment Outlook (seo_investment_outlook.php removes this * function and prints one), chart detail views (social_charts_admin.php), standalone templates (calculator, Nexus). * * @return string Absolute URL, or '' when the page should carry no canonical (search, 404, feeds). */ function ms_seo_canonical_url() { if ( is_404() || is_search() || is_feed() || is_preview() ) { return ''; } // Calendar app: /calendar/ is the hub; earnings, dividends and economics are their own pages (query args dropped). $cal = (string) get_query_var( 'ms_calendar_page' ); if ( '' !== $cal || is_page( 'calendar' ) ) { return in_array( $cal, array( 'earnings', 'dividends', 'economics' ), true ) ? home_url( '/calendar/' . $cal . '/' ) : home_url( '/calendar/' ); } if ( is_singular() ) { $post = get_queried_object(); if ( ! $post instanceof WP_Post ) { return ''; } $url = wp_get_canonical_url( $post ); // Only real multi-page posts keep a page number; /page/2/ on an ordinary page is the page itself. $page = max( (int) get_query_var( 'page' ), (int) get_query_var( 'paged' ) ); if ( $page > 1 && false === strpos( (string) $post->post_content, '' ) ) { $url = get_permalink( $post ); } return $url ? (string) $url : ''; } $base = ''; if ( is_front_page() ) { $base = home_url( '/' ); } elseif ( is_home() ) { $base = (string) get_permalink( (int) get_option( 'page_for_posts' ) ); } elseif ( is_category() || is_tag() || is_tax() ) { $term = get_term_link( get_queried_object() ); $base = is_wp_error( $term ) ? '' : (string) $term; } elseif ( is_author() ) { $base = (string) get_author_posts_url( (int) get_queried_object_id() ); } elseif ( is_post_type_archive() ) { $type = get_query_var( 'post_type' ); $base = (string) get_post_type_archive_link( is_array( $type ) ? reset( $type ) : $type ); } elseif ( is_date() ) { if ( is_day() ) { $base = get_day_link( get_query_var( 'year' ), get_query_var( 'monthnum' ), get_query_var( 'day' ) ); } elseif ( is_month() ) { $base = get_month_link( get_query_var( 'year' ), get_query_var( 'monthnum' ) ); } else { $base = get_year_link( get_query_var( 'year' ) ); } } if ( '' === $base ) { return ''; } $paged = (int) get_query_var( 'paged' ); if ( $paged > 1 ) { $base = trailingslashit( $base ) . user_trailingslashit( 'page/' . $paged, 'paged' ); } return $base; } /** * @return void */ function ms_seo_print_canonical() { $url = ms_seo_canonical_url(); if ( '' !== $url ) { echo '' . "\n"; } } // One writer: WordPress core's rel_canonical would print a second tag on singular pages. remove_action( 'wp_head', 'rel_canonical' );
Loading calculator...
Fetching data for CYRX...AI assistant
MarketSnap AI
Sign in to run Value AI Lens or the AI Case Engine.
Sign in