Title: HELP: custom comments link with plugin
Last modified: August 18, 2016

---

# HELP: custom comments link with plugin

 *  [oats](https://wordpress.org/support/users/oats/)
 * (@oats)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/)
 * Hello,
    I am trying to modify the comments link generated by wordpress, but I
   can’t seem to get the plugin to work. I am trying to filter/replace the “get_comments_link”
   function. If I change the source file, I get the change I want, but I can’t seem
   to get the plugin to do anything – the original function always gets called instead.
 * What am I doing wrong??
 *     ```
       //==================================================================
       // Comments Link Replacement
       //==================================================================
       function get_comments_link_hijack() {
       	...
   
       }
   
       /*
       THE ORIGINAL, DEFINED IN comment-template.php
       function get_comments_link() {
       	return get_permalink() . '#comments';
       }
       */
   
       // Create hook for wordpress
       add_filter('get_comments_link','get_comments_link_hijack');
       ```
   

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

 *  [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-585971)
 * You’re doing it wrong.
 * The hooks are used to place stuff into the areas that are created for it: wp_head(),
   wp_meta(), etc. You can’t add a hook to an already-defined function.
 * You can write a function based on the existing code, but you have to rename it,
   and then call it in. So instead of calling in your sidebar with get_comments_link()(
   as you normally would), you would use get_comments_link_hijack() to use your 
   version.
 *  Thread Starter [oats](https://wordpress.org/support/users/oats/)
 * (@oats)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586000)
 * Thanks for the reply… it sounds like what you are recommending is that I define
   a new function, and then update my template to use the modified function.
 * I was hoping for a solution which wouldn’t require changes to templates, but 
   just modify this function globally. Is it possible? Is there some other hook 
   I could use?
 *  Thread Starter [oats](https://wordpress.org/support/users/oats/)
 * (@oats)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586027)
 * Perhaps I can use this pluggable function technique? Can I plug any core function
   I want, or only certain functions?
 * [http://codex.wordpress.org/Pluggable_Functions](http://codex.wordpress.org/Pluggable_Functions)
 *  [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586246)
 * _it sounds like what you are recommending is that I define a new function, and
   then update my template to use the modified function._
 * Yes.
 * I don’t know about pluggable functions – never tried it. But if you’re trying
   to write a plugin for people to use, then you *do* want to define a custom function
   for them to edit their own theme for. You don’t want something that messes with
   the core code – what if they want to shut it off, or they decide they don’t like
   it?
 *  Thread Starter [oats](https://wordpress.org/support/users/oats/)
 * (@oats)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586339)
 * _But if you’re trying to write a plugin for people to use,…. You don’t want something
   that messes with the core code – what if they want to shut it off, or they decide
   they don’t like it?_
 * Umm, thats exactly what a plugin does – it doesn’t mess with the core code, and
   allows people to easily turn it on/off.
 *  [frames](https://wordpress.org/support/users/frames/)
 * (@frames)
 * [18 years ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586407)
 * I’m looking for the exact same thing without hacking the core or doing complex
   things.
 * What I simply want to do is change `#comments` for `#comentarios` (in Spanish)
   to the comment links. Looks like _get\_comments\_link_ is the function to change,
   which is in _comment-template.php_ (in the _wp-includes_ directory, of course).
   This is it:
 *     ```
       /**
        * get_comments_link() - Retrieves the link to the current post comments
        *
        * @since 1.5
        *
        * @return string The link to the comments
        */
       function get_comments_link() {
               return get_permalink() . '#comments';
       }
       ```
   
 * As doodlebee points out, defining a new function would work. But, _comments\_popup\
   _link_ makes use of _comments\_link_, which is at the same time making use of
   _get\_comments\_link_ again. That means, if I change the _get\_comments\_link_
   function to, say, _get\_comments\_link\_sp_, then I also have to change _comments\
   _link_ to _comments\_link\_sp_, and finally, _comments\_popup\_link_ to _comments\
   _popup\_link\_sp_. Changing at least one line in each function.
 * Like I say, that works, but it means copying and pasting three functions, then
   changing the code.
 * That’s a nightmare! Seriously, hacking the core would be easier if this is the
   only route. At least I would save the hassle (and possible errors) of copying
   and pasting each time the core code changes.
 * Plus, I think any other plugins or code that would use the ‘standard’ WordPress
   code would not work for me. Which means more _hacking_?
 * Furthermore, there’s other functions to be changed, such as _get\_comment\_link_.
   Again, more pain.
 * I have found out all of this without any PHP knowledge, but I feel there must
   be a way to make all of this much simpler.
 * Any advise or help would be much appreciated.
 * Cheers!
 *  [frames](https://wordpress.org/support/users/frames/)
 * (@frames)
 * [18 years ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586409)
 * To make things worse, I have found out that the original get_comments_link (as
   expected) is widely used not only in themes, but also in other parts of WordPress.
 * For instance, all the comments feeds (global and per-entry) and even worse, in
   admin sections. If I use a customised function, it will break both the feeds 
   and the admin.
 * Like I said, I don’t know any PHP, but I’d be happy to investigate this if anyone
   can shred some light here.
 *  [postedpost](https://wordpress.org/support/users/postedpost/)
 * (@postedpost)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586413)
 * I met this problem too. Fist I want add a filter, later want redeclare the function,
   of course cannot at PHP. Finally I just rewrite the **get_comment_link function**
   in [includes/comment-template.php](http://postedpost.com/category/wordpress/)
   file and make a note for check the change on every time apply patch or update.

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

The topic ‘HELP: custom comments link with plugin’ is closed to new replies.

 * 8 replies
 * 4 participants
 * Last reply from: [postedpost](https://wordpress.org/support/users/postedpost/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/help-custom-comments-link-with-plugin/#post-586413)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
