I am using wordpress 3.9.1 for one of the website. I am getting slow response around 35 seconds. I did investigation & found that wp_head is taking too much time. Further, I debug & found that a function inside wp-includes/plugin.php is causing it:

function do_action($tag, $arg = '') {
    global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;

    if ( ! isset($wp_actions[$tag]) )
        $wp_actions[$tag] = 1;

    // Do 'all' actions first
    if ( isset($wp_filter['all']) ) {
        $wp_current_filter[] = $tag;
        $all_args = func_get_args();

    if ( !isset($wp_filter[$tag]) ) {
        if ( isset($wp_filter['all']) )

    if ( !isset($wp_filter['all']) )
        $wp_current_filter[] = $tag;

    $args = array();
    if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
        $args[] =& $arg[0];
        $args[] = $arg;
    for ( $a = 2; $a < func_num_args(); $a++ )
        $args[] = func_get_arg($a);

    // Sort
    if ( !isset( $merged_filters[ $tag ] ) ) {
        $merged_filters[ $tag ] = true;

    reset( $wp_filter[ $tag ] );
   ///////////////////// PROBLEM STARTS FROM HERE //////////////////
    do {
        foreach ( (array) current($wp_filter[$tag]) as $the_ )
            if ( !is_null($the_['function']) )
                call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
    } while ( next($wp_filter[$tag]) !== false );
////////////////////////// PROBLEM AREA ENDS HERE ///////////////////


Problem exists in do..while loop as it is taking around 30 seconds to be executed. Please suggest me how to get rid of this slow response.

  • disable all plugins then enable them one by one to find the guilty one. Oct 13, 2014 at 19:32
  • @MarkKaplun Disabling plugins didn't work. But, I tried changing theme & it is working perfectly fine. But, My question is why am I getting slow response in case of MultiNews theme?
    – Apul Gupta
    Oct 13, 2014 at 19:43
  • It is hard to tell without looking at the code. Better to ask the developer to take a look at it. Oct 13, 2014 at 20:57
  • 1
    35 sec it's a huge time, it is likely the PHP timout, may be a symptom of a hook calling itself in an infinite loop.
    – gmazzap
    Oct 13, 2014 at 22:58

2 Answers 2


Well, do_action() is in plugin.php for a reason. It's intended for use by plugins, just like apply_filters(). This function is not the cause, it is just the middleman. It's like saying your pizza tastes bad because of the delivery guy - instead of the restaurant itself.

This is almost certainly caused by a plugin.

I suggest the plugin P3 (Plugin Performance Profiler) to analyze the performance of plugins. Some plugins are especially bloated (Jetpack, SEO Ultimate) but can be optimized by disabling unneeded modules.


Other plugins may be available if the GoDaddy brand is not for you, I dislike GoDaddy myself, but this plugin is great.

  • Thanks @RadGH I totally agree with your statement. But, even I disable all plugins, it takes time. The problem is in theme & not in plugins itself. I changed the theme & it works with all plugins. I want to investigate why it is slow for a certain theme. Can you please give me some suggestions?
    – Apul Gupta
    Oct 14, 2014 at 8:15
  • Try adding echo $tag: to the plugin.php file that you mentioned, temporarily. Run the page and see if there is an action that is running an abnormal amount of times (200+). Or add some echos throughout your theme (temporarily, again) and see which ones take awhile to appear. If you can narrow it down to a function or action name, you should be able to find it. Oct 14, 2014 at 15:10
  • do_action() is causing issues when called in wp_head(), I am not sure how to find further
    – Apul Gupta
    Oct 14, 2014 at 15:19

The do_action function is the function responsible for executing hooked actions.

WordPress works based on a system of "actions". Essentially, an action is a named point in the code generation process that other code can connect, or "hook", into and run their code at that specific point in time.

Now, there are thousands of these actions in WordPress, but the specific one you're referring to is the wp_head call. This is an action called by the wp_head() function. Its purpose is to let code put stuff into the generated header code of the HTML page. Things like Javascript and stylesheet links get output in the wp_head call, amongst other stuff.

You've narrowed it down to the section in wp_head where it calls the functions that are hooked into wp_head, so really, you haven't narrowed it down at all. Anything hooked to wp_head could be the problem.

So, given that you've narrowed it down to a problem in the theme, and given that the theme is not a free one so we cannot see their code, then I'd say to look at the code of the theme, and look for these specific types of things:

  1. Anything hooked to wp_head. Obvious. This will be anything that does add_action('wp_head', ... );. The second parameter will be the name of a function that gets called on the wp_head action.

  2. Anything that looks like it might be particularly slow. For example, if some function is making a call to the web, to get something via an http request, that could be the cause.

  3. Anything with a name involving "scripts" or "styles". These are always output into the head, and so may be involved.

Now, you can also use a couple plugins to help you debug your site.

Debug Bar is a base plugin you'll need to use the next one. It adds a "debug" bar to the admin bar on your page, which shows you details about what happens when your site is running and creating a page. To use it, you will need to install it, activate it, and turn on the WP_DEBUG setting in your wp-config.php file.

Debug Bar Slow Actions adds a "Slow Actions" list to the Debug Bar output, telling you how long each action takes to run, and what functions are connected to it and being run by it. This will let you narrow down what exactly is making it slow and trace it to the function responsible.

  • Can you please tell me where to look in the theme for hooked actions? As when I change theme, it works.
    – Apul Gupta
    Oct 14, 2014 at 8:16
  • They can be anywhere in the theme. You need to search all the PHP files. Start with the functions.php file, and any files it includes.
    – Otto
    Oct 14, 2014 at 16:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.