I’ve figured out the solution to my problems. Here’s what I did…
Note:
This is considering the posts, thus comments, are under the ‘Article‘ post-type, which thus create the permalink such as this: site.com/article/post-name/#comments.
Adjustments should be made for other uses.
To fix problem #1 & #3:
if ( !is_admin() )
add_filter('get_comment_link', 'my_comment_post_redirect');
function my_comment_post_redirect($location){
// Retrieve the URL based on current language up to the post-type ('article')
$currUrl = preg_replace('/(.*article\/).*/', '$1', $_SERVER["HTTP_REFERER"]);
// Retrieve the URL from the post name to the location of the comment
// (ie. comment page & number/ID)
$cmntPage = preg_replace('/.*article\/(.*)/', '$1', $location);
// Comment page #1 has special redirection, thus...
$cmntPageNum = preg_replace('/.*comment-page-(.*)\/.*/', '$1', $cmntPage);
// If on first comment page...
if ($cmntPageNum == 1) {
// ...then get rid of comment page from permalink
$cmntPage = preg_replace('/(.*)comment-page-.*\/(.*)/', '$1$2', $cmntPage);
}
return $currUrl.$cmntPage;
}
UPDATED: The above code will also affect comment links in the back-end so I added
if ( !is_admin() )
at the top to prevent it from happening.
For problem #2, I created a function for each link (next & previous):
function def_get_next_comments_link($label, $max) {
// Get the complete code generated by the function
// (which includes the <a> tag)
$navLink = get_next_comments_link($label, $max);
// Retrieve the base URL up to the post-type 'article'
$baseUrl = preg_replace('/.*(http:.*article\/).*/', '$1', $navLink);
// Replace the base URL with the one for the current language
return str_replace($baseUrl, qtrans_convertURL($baseUrl), $navLink);
}
function def_get_previous_comments_link($label) {
// Get the complete code generated by the function
// (which includes the <a> tag)
$navLink = get_previous_comments_link($label);
// Retrieve the base URL up to the post-type 'article'
$baseUrl = preg_replace('/.*(http:.*article\/).*/', '$1', $navLink);
// Replace the base URL with the one for the current language
return str_replace($baseUrl, qtrans_convertURL($baseUrl), $navLink);
}
Then I just called the functions where the links are.
This worked for me. 🙂