Title: Override core function without hack
Last modified: August 19, 2016

---

# Override core function without hack

 *  Resolved [surfgatinho](https://wordpress.org/support/users/surfgatinho/)
 * (@surfgatinho)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/override-core-function-without-hack/)
 * Basically, I want to override a function (wp_get_attachment_link) in wp-includes/
   post-template.php without hacking the file itself.
 * I’ve tried redefining the function in my theme functions.php but that doesn’t
   seem to work.
 * Any suggestions how I can do this?
 * Thanks

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

 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [15 years, 3 months ago](https://wordpress.org/support/topic/override-core-function-without-hack/#post-1921906)
 * > without hacking the file itself.
 * That’s a very good idea, give this article a read. It might help.
 * [http://www.catswhocode.com/blog/how-to-overwrite-wordpress-core-functions](http://www.catswhocode.com/blog/how-to-overwrite-wordpress-core-functions)
 *  Thread Starter [surfgatinho](https://wordpress.org/support/users/surfgatinho/)
 * (@surfgatinho)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/override-core-function-without-hack/#post-1922038)
 * Ended up overriding get_attachment_link instead. There appears to be a filter
   for it. Don’t 100% understand it but it works!
 *     ```
       function custom_get_attachment_link($result='', $id = false) {
   
          //NEW CODE IN HERE///////////////////////////////
   
       	return apply_filters('custom_get_attachment_link', $link, $id);
       }
   
       add_filter('attachment_link', 'custom_get_attachment_link', 1, 2);
       ```
   
 *  [yetimade2](https://wordpress.org/support/users/yetimade2/)
 * (@yetimade2)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/override-core-function-without-hack/#post-1922255)
 * That article doesn’t do anything when applied to this situation.
 * But, dude – surfgatinho – that works! Dude, I owe you one!!!
 * How did you figure this out? If you could post how you figured this out – train
   of thought, and give a little explanation, that would be amazing. And, let me
   know if there’s any way that I can help you with anything!
 * Thanks!
    JC

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

The topic ‘Override core function without hack’ is closed to new replies.

 * 3 replies
 * 3 participants
 * Last reply from: [yetimade2](https://wordpress.org/support/users/yetimade2/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/override-core-function-without-hack/#post-1922255)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
