WordPress – Hook into another hook

This is a hack, so if you know a better way of doing this please tell me. I wanted to add a filter to get_permalink, but only when get_permalink was called from a function in another plugin.

Here’s the function I wanted to hook into, it’s part of the Digg Digg plugin and you’ll find it in the digg-digg.php file (In the example below I’ve removed most of the code):

This is what I did:

wp_debug_backtrace_summary return a comma separated string of functions that have been called to get to the current point in code.

So why did I need this hack? I needed to preserve my social sharing counters after I changed my permalink structure. My old permalink was /archives/%year%/%monthnum%/%day%/%postname%/ and the new is /%postname%/. I Changed my permalink structure on the 12.1.2013

The working hack, which I added to the child theme functions.php, is:

Demo: Go to http://soderlind.no/running-wordpress-locally-on-mac-os-x-lion/ and click on tweet in the Digg Digg floating bar, and you’ll see that the old permalink is preserved.

7 thoughts on “WordPress – Hook into another hook

  1. Beltrán

    Hey Per! Thanks for posting this, I’m trying to make it work in my wp but I not having luck, so far.
    I’m adding the function in my theme’s functions.php file but it is not working.
    I set the date to 2.2.2014 and I have removed the /archives/ part in the date string because my url used to be “url/y/m/d/permalink”. I don’t really know if I have to make any other adjustments. Also I wonder what the numbers “20, 3” in the filter are for.
    I paste my code in case you want to check it. Thanks again, a lot.

    1. Beltrán

      Just add that the function is returning to zero my digg digg counter. Maybe it’s useful for you to know. Cheers!

        1. Beltrán

          Hello Per!
          Sorry I didn’t check this before.
          My url is http://aulacm.com
          I did not find the way to do this hack to Digg Digg plugin, so now is everything back to the original settings. If you have any ideas to make this work it Would be great. I’m gonna try again. Thank you!!


Leave a Reply

Your email address will not be published. Required fields are marked *