Opened 13 years ago
Last modified 6 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 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | Canonical | Keywords: | needs-patch dev-feedback |
Focuses: | Cc: |
Description
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: http://example.com?some_param=some_val&cat=3,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 http://example.com?cat=3,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?
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 http://example.com/?cat=3&some_param=some_var (‘some_param’ is odd and unnecessary parameter) it makes parameter will be in every another page like http://example.com/?cat=3&some_param=some_var&paged=2 for example.
Conclusion. Now we can retrieve canonical URL for single post (or single page or single attachment) only.