Make WordPress Core

Opened 12 years ago

Last modified 5 years ago

#20283 new enhancement

Create new variable or function in $wp_query object to get canonical URL of any site's page

Reported by: egorpromo's profile egorpromo Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Canonical Keywords: needs-patch dev-feedback
Focuses: Cc:


For the sake of Search Engine Optimization it's recommended to set canonical URL inside <link rel='canonical'> tag in any site's page. Incorrect URL can exist in search engine index. For example:,4. URL points to categories with id equals 3 and 4, but we have another unnecessary parameter 'some_param'. It's malicious! We must set canonical URL to,4.
So It's advance to have canonical URL generated some way. I propose to set function or variable inside WP_Query class to retrieve canonical URL to any opened page.

In WP_Query we have variable WP_Query::query which consists of all necessary parameters for that propose. But we must use $wp_rewrites also.
Any thoughts?

Change History (4)

#1 @egorpromo
12 years ago

For single posts it is possible to get canonical URL by used get_permalink() function or if we have paged post by used some function that will be in future versions.

For any archive page there is no decision. It is possible to use get_pagenum_link() function in way like get_pagenum_link($wp_query->query_vars[ "paged" ]), but it is odd. If we have URL with unnecessary parameter like (‘some_param’ is odd and unnecessary parameter) it makes parameter will be in every another page like for example.

Conclusion. Now we can retrieve canonical URL for single post (or single page or single attachment) only.

Last edited 12 years ago by egorpromo (previous) (diff)

#3 @chriscct7
10 years ago

  • Keywords needs-patch dev-feedback added

#4 @swissspidy
9 years ago

See also #18660.

Note: See TracTickets for help on using tickets.