Try specifying the priority for your function. You will also want to remove the default canonical link before adding your modified one. This worked on my site:
function canonical_for_comments()
{
global $cpage, $post;
if (!empty($cpage) && $cpage > 0) {
remove_action('wp_head', 'rel_canonical');
echo '<link rel="canonical" href="' . esc_url(get_permalink($post->ID)) . '" />';
echo "\n";
}
}
add_action( 'wp_head', 'canonical_for_comments', 9 );
Related Posts:
- How to wrap submit button of comment form with div
- What for is the table “wp_commentmeta” exactly?
- Custom comment type based on thread level
- How to add internal, revision comments to page updates
- Comment Reply javascript
- Running a function on comment status change
- Hook to edit an column on comments screen?
- Comment Author Name In Reply Form
- Completely disable comments
- how to make author to write comment on only his own posts?
- How do you remove the ability for a user to make a comment or post on a page?
- Customize reply form different to comment form
- Add delete, approve, spam Links to Comments
- If new comment posted in custom post – send notification to custom email from custom field
- How to allow commentetors to get notifications on replies to their comments?
- WP_Comment_Query with 5 top level comments per page?
- Can I have two single.php files and have one display just the post and the other display comments for that specific post?
- How can I change the link in comment form “Log in to post a comment”?
- WordPress admin bar showing pending comments which cannot be selected or modified after deleting parent page
- Get only one comment per post with get_comments
- What is the correct/safe way to delete all comments?
- Comments: Approve when admin Replies, from the Front end
- Setting comment text as required
- Draft / schedule comments?
- How to insert Comment metadata via REST API
- How to remove these comments and html tags from the content?
- How to create a link to jump to “Leave a comment” part?
- Opening all posts for comments
- Unix timestamp for post comment
- Show only if x comments?
- Display WordPress commenter nice name
- In wp_list_comments(), what is a short_ping?
- Changing the comments link produced by the get_comments_link() and get_comments_pagenum_link() functions
- How to display nothing (instead default) when no user gravatar is present?
- Check if someone recently commented in one of my posts
- How to query comments only for the current post?
- Sync comment data
- How to change avatar of the comment author using comment ID?
- Comment displaying full name even after setting another display name?
- How to move comments box above comments
- save_post action hook for comments
- Ability to leave comments broken
- How to disable comment flood temporarily in a single scope
- How to create a seperate commenting system?
- Change how many approved comments must user have
- Only admin can see comments on post or page
- Count comment threads, not total comments in a post
- Show comments of a user post only when they are login
- Comments from vbulletin topic [closed]
- wp.getComments is returning nill, when i called from my iphone app [closed]
- How to override wp_insert_comment()
- Admin can enter JavaScript – potential security risk?
- custom hooks before a comment is updated/edited in the database
- How can I get list of emails of users who commented on a post?
- How modify the comment content persistently based on $wp_query?
- Displaying Posts Depending on Number of Comments and Latest Comments?
- Disable only the comment form/box itself?
- How to hide wordpress post comment form for specific role
- How to customize the title from comments form?
- How to display comment meta under each comment content
- Why there is still an approved comment after deleting all?
- Custom comment field not showing when logged-in
- Comments and post dates not showing up correctly on “posts page”
- comments_popup_link() – how to load different classes/images according to different comment condition?
- Comments numbering on multiple pages
- disable reply comments on depth equals 2
- Problem with comment box
- How to show last comment on hover?
- Users moderate own comments
- Problem in getting user comments permalinks
- Permalink structure and dedicated comment pages
- Critical error – can’t post comments
- Is there a way to only allow certain user ranks to comment on a post
- How to add code for wp-comments-post.php over functions.php?
- Is there a way to export WordPress comments to a non-wordpress, HTML coded site?
- Create another comment section for WordPress
- How to get the current post ID in comments.php?
- Change commenters email to display name
- Faulty comment.php, comments won’t show up after posting?
- Change hyperlink to User Registration page instead of WordPress login page
- How to import facebook comments to WordPress database?
- How to enable reply button on mostly deeply-nested comments? [closed]
- Why is a old comment reply comment appearing at end of comment list as well
- Can’t check “Allow people to post comments on new articles” option
- Adding Parameters to get_comment
- Comments from other blogs are getting added to my blog?
- Disqus resetting comment count to 0
- Deleting users do not deletes coments
- Auto-deleting comments that trigger the blacklist
- modifying the comment form
- Show count of all comments by meta_value from a users posts
- How to resolve 404 errors for wordpress comments/feed when I have disabled comments
- Where to insert get_comments?
- Overflow and Comments
- How to modify the comments list in WP & BuddyPress? [closed]
- Is there a plugin that can replace WP comments with Facebook comments as used by TechCrunch? [closed]
- how to remove indent from twently eleven comments reply
- list / show comments of post author in special page
- How to use Disqus for some categories, and FB comments for others?
- Why nobody is answering my question? [closed]