Per Søderlind

I code for fun

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 and click on tweet in the Digg Digg floating bar, and you’ll see that the old permalink is preserved.


WordPress Debug Bar, List Script & Style Dependencies


WordPress Twitter Widget Pro with mentions


  1. You can possibly try remove_filter, in combination with checking to see if the plugin using the filter is active.

  2. 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.

    • Beltrán

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

      • Per Søderlind

        What’s the url to your site?

        • Beltrán

          Hello Per!
          Sorry I didn’t check this before.
          My url is
          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!!

  3. This code was a lifesaver for me! Thanks for the ingenious solution.

    I got it working with the Genesis Simple Share plugin. Here’s a gist of the code I used.

Leave a Reply

Powered by WordPress & Theme by Anders Norén