• Resolved johnh10

    (@johnh10)


    WordPress: 6.8.1, AISEO: 4.8.4.1

    Without AISEO, my comment reply links work and look like:

    <a rel="nofollow" class="comment-reply-link" href="https://domain.com/2024/06/post/?replytocom=1398#respond" data-commentid="1398" data-postid="829" data-belowelement="comment-1398" data-respondelement="respond" data-replyto="Reply to Anonymous" aria-label="Reply to Anonymous">Reply</a>

    After I activate AISEO, my comment reply links don’t work and look like

    <a rel="nofollow" class="comment-reply-link" href="#comment-1398" data-commentid="1398" data-postid="829" data-belowelement="comment-1398" data-respondelement="respond" data-replyto="Reply to Anonymous" aria-label="Reply to Anonymous">Reply</a>

    So with AISEO, it now links to non-existing anchor text and nothing happens. How is this supposed to work? Is AISEO supposed to add in those anchor tags somehow? I’m not sure what to look for.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @johnh10 ,

    Thanks for reaching out!

    You’re absolutely right to be concerned about the change in your comment reply links when AIOSEO is activated. Let me explain what’s happening and reassure you about the functionality.

    What’s Happening

    When AIOSEO is activated, it automatically transforms your comment reply links from:

    https://domain.com/2024/06/post/?replytocom=1398#respond

    To:

    #comment-1398

    This is part of AIOSEO’s Crawl Cleanup feature, which is designed to:

    • Remove unnecessary query parameters from URLs for better SEO
    • Create cleaner, more user-friendly URLs
    • Prevent duplicate URLs in search engines (the same page with different query parameters)

    The Good News: Functionality Should Work Fine

    Despite the change in URL format, the comment reply functionality should work perfectly fine. The #comment-1398 anchor should still scroll to the comment and open the reply form. The JavaScript that handles comment replies looks for the data-commentid attribute (which is still present) rather than relying on the URL format.

    Why This Happens?

    AIOSEO considers the ?replytocom parameter unnecessary because:

    1. It creates duplicate URLs for the same content
    2. It can confuse search engines during crawling
    3. The anchor-based approach is cleaner and more SEO-friendly

    If You Want to Restore the Original Format

    If you prefer to keep the original WordPress URL format, you can add this code snippet through a plugin like WP Code:

    // Override AIOSEO's comment reply link modification
    add_filter( 'comment_reply_link', function( $link ) {
        // Restore the original WordPress format
        return preg_replace( 'href=(["\'])#comment-(\d+)', 'href=$1?replytocom=$2#respond', $link );
    }, 20 );

    This will restore your links to the original ?replytocom=1398#respond format while keeping AIOSEO’s other SEO benefits.

    Testing the Functionality

    To verify that comment replies are working correctly:

    1. Try clicking on a “Reply” link
    2. The page should scroll to the comment
    3. A reply form should appear below the comment
    4. You should be able to submit a reply

    If the reply functionality isn’t working, the issue is likely unrelated to AIOSEO and might be a theme or plugin conflict.

    Let me know if you need any clarification or if you’re experiencing any issues with the actual reply functionality!

    Thread Starter johnh10

    (@johnh10)

    Okay, I found the issue. AISEO assumes the comment id attribute is “#comment-[ID]” and my theme had a prefix so it was actually “#XX-comment-[ID]”. Therefore the AISEO anchor would not match. Fixed and all is good again. Thanks!

    Also, note for anyone who might use it, the WP Code snippet above is missing the delimiters in the first parameter.

    Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @johnh10,

    That’s fantastic to hear — great job tracking that down!

    Great catch on the missing delimiters in the snippet — you’re absolutely right! For anyone using it, the corrected version should look something like this:

    add_filter( 'comment_reply_link', function( $link ) {
        // Restore the original WordPress format
        return preg_replace( '/href=(["\'])#comment-(\d+)/', 'href=$1?replytocom=$2#respond', $link );
    }, 20 );

    Thanks again for the follow-up and for helping others by sharing your fix!

    If you ever run into anything else, we’re always here to help.

    Thread Starter johnh10

    (@johnh10)

    Sorry to open this again, but the Crawl Cleanup feature only works on pages with a single post.

    If comments are allowed on the homepage and archive pages (which have multiple posts), then this reduction to <code>#comment-1398</code> does nothing when the reply link is clicked. It only works when there is a single post on the page.

    Is it possible to fix?

    Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @johnh10,

    Thanks for your reply!

    To fix this while keeping AIOSEO’s SEO benefits on single post pages, you can use the following snippet:

    /**
     * Fix AIOSEO comment reply links on archive pages
     * 
     * Restores ?replytocom={id}#respond on archive pages where anchor links may not work
     * while preserving AIOSEO's anchor format on singular pages.
     */
    add_filter( 'comment_reply_link', function( $link ) {
    	if ( ! is_singular() ) {
    		return preg_replace( '/href=(["\'])#comment-(\d+)/', 'href=$1?replytocom=$2#respond', $link );
    	}
    	return $link;
    }, 20 );

    You can add this using a code snippet plugin like WPCode or directly in your theme’s functions.php file.

    This way:

    • On archive pages and the homepage, comment reply links will work as expected.
    • On singular posts, you still get the SEO-friendly cleaned-up links.

    Thanks again for helping make things better for others too.

    Let me know if you need anything else!

    Thread Starter johnh10

    (@johnh10)

    This is very close!

    With the above code, a comment reply link on the index/archive page will now look like

    https://domain.com/2024/06/post/?replytocom=1398#respond

    but when clicked, AISEO changes the url to

    https://domain.com/2024/06/post/#comment-1398

    so the single post loads then focuses on the comment the person clicked the reply link for, instead of the #respond box itself.

    Is there a way to stop AISEO from changing the url when the single post first loads? Hope that makes sense.

    Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @johnh10 ,

    Thanks again for the follow-up.

    What’s happening is AIOSEO’s Crawl Cleanup feature strips ?replytocom=… when the single post loads, replacing it with #comment-{id}. Since anchor fragments like #comment-1398 aren’t sent to the server, we can’t keep #respond in place at that point, so the form doesn’t auto-open.

    You’re already using the archive-only snippet to restore ?replytocom=…#respond on archive/home pages. Let’s build on that with a small JavaScript snippet to restore reply behavior when the post loads:

    // Add to functions.php or WPCode
    add_action( 'wp_enqueue_scripts', function () {
    	if ( ! is_singular() ) {
    		return;
    	}
    
    	wp_enqueue_script( 'comment-reply' );
    
    	$inline = <<<JS
    (function () {
    	document.addEventListener('DOMContentLoaded', function () {
    		var m = location.hash && location.hash.match(/^#comment-(\\d+)$/);
    		if (!m) return;
    
    		var id = m[1];
    		var link = document.querySelector('.comment-reply-link[data-commentid="' + id + '"]');
    		if (link && typeof link.click === 'function') {
    			link.click();
    
    			var textarea = document.querySelector('#respond textarea, #comment');
    			if (textarea) textarea.focus();
    		} else {
    			var respond = document.getElementById('respond');
    			if (respond && respond.scrollIntoView) {
    				respond.scrollIntoView({ behavior: 'smooth', block: 'start' });
    			}
    		}
    	});
    })();
    JS;
    
    	wp_add_inline_script( 'comment-reply', $inline, 'after' );
    }, 20 );

    What This Does:

    • On archive/home pages, links still use ?replytocom=…#respond — your earlier fix handles that.
    • On single post loads, if the URL includes #comment-{id}, this script auto-clicks the correct “Reply” link to move the form under the right comment and focus it.
    • Keeps AIOSEO’s SEO benefits intact.

    Please let me know how that goes or if you have any questions.

    Thread Starter johnh10

    (@johnh10)

    So far, it’s working great! Maybe add this functionality to the plugin? Comments are allowed on archive pages if the global var $withcomments is set to true.

    Plugin Support Shivam Tyagi

    (@shivamtyagi)

    Hi @johnh10,

    Glad to hear it’s working well for you!

    I’ll pass your suggestion along to our development team. Adding this functionality (and the $withcomments consideration) directly into the plugin could help other users in similar situations.

    While I can’t promise a timeline, it’s definitely useful feedback for improving how we handle ?replytocom and anchor behavior without losing the SEO benefits.

    Thanks again for testing and for sharing your input!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Comment reply links do no’ is closed to new replies.