Support » Developing with WordPress » get_the_permalink printing comment number

  • I am trying to put up a different “Leave a comment” link on the blog page based on whether Disqus plug-in is loaded or not. I am using the following piece of code:

    <a class="comment-link" href="<?php
    	include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    
    	if (is_plugin_active('disqus-comment-system/disqus.php')) {
    		$custom_comment_link = get_the_permalink();
    		$custom_comment_link = substr($custom_comment_link, 0, strlen($custom_comment_link) - 1); /* remove trailing slash */
    		echo $custom_comment_link . '#disqus_thread';
    	} else {
    		echo get_comments_link();
    	}
    	?>">
    	
    	Leave a comment
    
    

    If Disqus is not active, the correct “Leave a comment” is being shown. However, if Disqus is loaded, it shows “<comment number> Comments” (with the comment number coming from WP comments, not Disqus).

    I am a bit baffled as to why this is happening. Any help would be highly appreciated.

    • This topic was modified 3 years, 12 months ago by astatine85.
    • This topic was modified 3 years, 12 months ago by astatine85.
    • This topic was modified 3 years, 12 months ago by astatine85.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @astatine85,

    I was going to tell you to ask for help in the support forums for the plugin, but it seems like there’s not much activity there. Since there’s no way for Disqus to filter the “Leave a comment” string, my best guess would be that Disqus overwrites the contents of the link in JavaScript.

    Try changing the #disqus_thread hash to something else, and see if it still shows “[comment number] Comments”.

    — Anders

    Thread Starter astatine85

    (@astatine85)

    @anlino Yes I tried changing the link away from #disqus_thread. But the problem still persists. This leads me to believe that WP API has some bug which is overriding this. I haven’t been able to identify which or where though.

    I have applied a temporary fix with JS that forcefully overwrites the links.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_permalink printing comment number’ is closed to new replies.