• Resolved surfgatinho

    (@surfgatinho)


    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

    (@jdembowski)

    Forum Moderator and Brute Squad

    without hacking the file itself.

    That’s a very good idea, give this article a read. It might help.

    https://www.catswhocode.com/blog/how-to-overwrite-wordpress-core-functions

    Thread Starter surfgatinho

    (@surfgatinho)

    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);

    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.