Alister Cameron // Blogologist

Changing the world. One blog(ger) at a time.

A great little trick for debugging WordPress problems

This week I upgraded a new client’s WordPress blog from version 2.6 to 2.9.2. All went just dandy.

Then today he emailed me to say that he’d noticed his post excerpts were not appearing where they were supposed to, in single post pages. On closer inspection I noticed that the excerpts displayed fine on the homepage, but — despite the same exact code being used — they weren’t showing up on single post pages. In both cases the the_excerpt() function was being used without parameters. Weird.

How would you go about debugging this one?

My immediate thought was to blame a plugin. Why? Because WordPress’s great coding strength is also its weakness — hooks and filters give plugin authors the ability to mess with the output of “core” WordPress functions. But it’s really hard to tell if any messing around is going on, in order to debug problems.

Question then: how do you figure out if one or more plugins is using a hook/filter to mess with the output of a given WordPress function?

If you have shell access to your WordPress host I’ve got a little treasure for you today. A simple enough shell command that will make your life a lot easier. (If you’re a “real” programmer you’ll almost certainly know about this already, but if you’re not, you’re gonna love it!)

Now, shell access (SSH) gives you “command-line” control of the operating system on which your WordPress blog resides. If your hosting provider has given that to you and you know how to use it, you can do cool stuff like ZIP up all the content in one hit so you can back it up really easily, say. Lots of fun to be had.

Today I want to show you how to return search results for all the instances where a certain string appears in your plugins’ PHP files. That’s how we’re going to debug my problem with the the_excerpt() function today.

Here’s the command to run at your SSH prompt when you’ve navigated into your wp-content/plugins directory:

find . -name \*.php -exec grep mystringhere {} +

(Note that on older systems that last plus sign might need to be replaced with a semicolon “;”.)

That command simply isolates all php files and searches through each in turn for each occurrence of “mystringhere”. For each occurrence it finds, it shows you that line of code preceded by the filename and line number. Easy!

Because I don’t like the black and white of my Terminal application, I then copy out all the results found into my code editor, so that I get to see the code in all the pretty colours that Coda puts it in. That’s up to you.

For purposes of example, here are the results I got from my client’s plugin directory (pops up a new window).

Yes it looks like a huge mess, but you can see now that it’s really easy for me, in my code editor, to search through all that for “add_filter” and “add_action”, to see where any plugin is messing with the output of the the_excerpt() function.

What all that search results mess (see link) tells me is that there are seven plugins that may be the culprit. In my case, I was fairly sure the Organize Series plugin wasn’t supposed to be active, and when I deactivated it… HEY PRESTO… problem solved. The excerpt came back!

If your hosting provider doesn’t give you SSH (or you’re not prepared to pay extra to get it), all is not lost… if you’re a Mac person. Download a backup of your site to your local machine, and then run the same command locally (from the plugins directory), using Terminal.

Comments welcome on what may be a good Windows equivalent approach.


Note: Commenter website links are not no-followed, in case
you were wondering... I believe in rewarding commenters!

  1. Posted 9 years, 2 months ago // Permalink

    If I understood this correctly, it should have been much easier than using SSH.

    All you need is Notepad++.

    Download all the Plugin files from your WordPress install and Open then all in Notepad++ (Select All and hit enter).

    Now Open Find Dialog and click “Find in all Open Documents” after adding your search string like “add_filter”.

    You will have all the search results listed along with the file and location.

    Hope that helps people who do not have SSH or a MAC. like me 🙂

  2. Alister Cameron
    Posted 9 years, 2 months ago // Permalink


    I find that “little” step of downloading all the plugin files to be painful! Leaving all the plugin files on the server is surely easier.

    But I agree that you have offered a good solution for PC people! Thanks.

  3. Posted 9 years, 2 months ago // Permalink

    You are awesome! I had the same post excerpt problem and I don’t have SSH so I just deactivated the plugin like you and Problem solved. Thanks a bunch you really saved me.

  4. Posted 9 years, 2 months ago // Permalink
  5. Posted 9 years, 2 months ago // Permalink

    Wicked trick, i was too in-countering problems with wordpress after i updated. Plugins to solve a problem is the easy way out, however solving the problem is the ultimate achievement.

  6. Posted 9 years, 2 months ago // Permalink

    Thanks for the advice in the article and the notepad idea in the comments is also helpful!

  7. Posted 9 years, 2 months ago // Permalink

    Much appreciated this effort. I enjoy using this all the time.. nice ..

  8. Posted 9 years, 2 months ago // Permalink

    WordPress and Technology has no boundaries, That’s why i search useful tips related to wordpress all the time. Some I got here.

  9. Posted 9 years, 2 months ago // Permalink

    Wouldn’t using the following be a reasonable solution for those working from the windows command prompt?:
    for %f in (*.php) do find “mystringhere” %f

    This is something I’ve been using for 20 or 30 years since the days of DOS.

  10. Posted 9 years, 2 months ago // Permalink

    WordPress is such a mess, lots of bugs, I would’t go for the latest version until it’s more stable, thnaks for these tips.

    Larissa from Paraguay.

  11. Posted 9 years, 1 month ago // Permalink

    Geez, this is a real time saver. My approach has always been to disable all my plugins and see if that fixed the problem. Then add them back one at a time to figure out who the culprit was.

    This is much more efficient. Thanks for the great debugging tip.

  12. Posted 9 years, 1 month ago // Permalink

    I’ve really enjoyed the various articles here and the blogs. There is so much information here that I couldn’t finish it all in one day. Thanks for this, it’s great.

    I look forward to learning so much from this site. Thanks so much

  13. Posted 9 years, 1 month ago // Permalink

    WP is one of the best CMS. Larissa, we are waiting to try your own CMS! :p

  14. Posted 9 years ago // Permalink

    I just tried this on a couple blogs I’m working on and it worked great! That has been one of the most frustrating things I have run into as an self-taught WordPress guy. Thank you!

  15. Posted 8 years, 12 months ago // Permalink

    This is a great timesaver. I didn’t realize I could do this through SSH… I’ve been using a virtual machine with MacOS installed on it in order to run it “locally” within the virtual machine and do pretty much the same thing. I feel silly now for not realizing I could just use SSH directly on the server. Thanks!

  16. Posted 8 years, 11 months ago // Permalink

    This is a wonderful post! I’ve been making a living as an internet marketer for 2 years now. I do it mostly through article marketing. In fact, I’ve written an ebook that explains exactly how to do it and I’m giving it away for free. That’s been a great strategy that has brought me a lot of traffic.

  17. Posted 8 years, 11 months ago // Permalink

    Hey Alister,
    Thanks for this excellent trick. It will really help a lot of people. I shared it with my friends on Facebook and Twitter because I know a lot of my friends need it.

  18. Posted 8 years, 10 months ago // Permalink

    5 Ways to Debug WordPress
    1. WP_DEBUG
    4. The ‘all’ and ‘shutdown’ hooks
    5. Core Control

  19. Posted 8 years, 10 months ago // Permalink

    I’m a little hesitant to upgrade because of unresolved bugs in the latest version. Slowly, tips and tricks like this is making me gain my trust and confidence.

  20. Posted 8 years, 10 months ago // Permalink

    Thanks this is a time saver, your blog is full of usefull stuff – one I keep visiting, thanks

  21. Posted 8 years, 9 months ago // Permalink

    Hi again, it seems like I am just about the only one commenting here – maybe I am playing catch up, I have got to admit it is pretty scary trying new things on my blog, but one thing I am learning you have to go for it otherwise you will be left behind. I feel like I am starting from way back. Anyone who reads this I could you use some help on how to remain constant on google, got to no.3 but cant seem to stay there longer than a few days?

  22. Posted 8 years, 9 months ago // Permalink

    Great article! Thanks a lot. Very useful blog in general.

  23. Posted 8 years, 7 months ago // Permalink

    I’m seriously so sick of the new WP updates. Things always go wrong for me when migrating content, using plugins, etc. If you’re content with the level of security for your current edition, don’t even bother upgrading.

  24. Posted 8 years, 6 months ago // Permalink

    Thanks for this post. Everytime I have a problem with WP it usually has to do with one of the plugins. This will save me some time for sure.

  25. Posted 8 years, 2 months ago // Permalink

    pretty useful workpress trick. Thanks!

  26. Posted 3 years ago // Permalink

    Thanks for the excellent help and for saving me, I recently encountered a problem in my word press plugin and now it has been fixed.

Post a Comment

Your email is never published nor shared. Required fields are marked *

  • My Posts in Your In-box!

    Enter your email address here for instant updates in your inbox, whenever I post something new.
    Your email address is in safe hands. Relax!
© Copyright 2010 Alister Cameron. All Rights Reserved Theme // Sitemap // RSS