How to Fix: function ‘new_excerpt_more’ not found or invalid function name


The other day I discovered an error message in a WordPress website along the following lines:

“call_user_func_array() expects parameter 1 to be a valid callback, function ‘new_excerpt_more’ not found or invalid function name in /wp-includes/class-wp-hook.php”.

This error was triggered when I activated The Events Calendar on a website that had, until this point, been working correctly. My first thought was that this was related to the installation of the Events Calendar plugin, but upon checking the website’s error log I could see this error going back way before I installed the plugin.

My first port of call was Google to see if anyone else had this problem. Sure enough, people were reporting it. However, the most common advice was to diagnose the issue by deactivating all the plugins on the website and changing the theme. On a live website this isn’t really practical, and short of creating a duplicate staging website (which would have been my last resort) I needed a faster solution.

The first thing to note that this is nothing to do with poor old class-wp-hook.php, which is basically a good kid who’s got in with a bad crowd. The real culprit is a function called ‘new_excerpt_more’, which is being marked as invalid or not found. The first task is therefore to find out where this function is being called. By process of elimination, I concluded that none of the plugins on the website were calling this function – there are only a few, and none of them seemed like it would need to mess with the WordPress excerpts. To double check you could turn them off one-by-one (done out of hours, this is a much safer task on a live website than changing the theme). If by some chance this fixes your problem, then you know to either replace the plugin with an alternative, or go back to the developer and ask for help (or failing that, ask us!).

Assuming it’s not a plugin, then the likely culprit is your theme, specifically your functions.php file. Download a copy of this via FTP, and search down the document until you find the phrase ‘new_excerpt_more’ – if this shows up, then you have found the problem. What you’ll need to do from here depends on where your theme came from. If you bought your theme from a third-party developer then the simplest solution is to go back to them and ask them to update the theme with a fix – you can then update your copy of the theme and it should resolve the problem. However, if this is a bespoke theme or is no longer supported by the original developer then you’ll need to fix it yourself. Luckily, it’s pretty simple.

The problem, ultimately, is that this function, new_excerpt_more, isn’t being defined anywhere. Assuming you have found where it is being called, you just need to define the function above where it is being called. There’s a bit of info on it in the WordPress Codex here, but the specific code you need to add is as follows:


function new_excerpt_more($more) {
global $post;
return '<a class="moretag" href="'. get_permalink($post->ID) . '"> More...</a>';
}

Paste this into your functions.php file just above where new_excerpt_more is called, then save and upload this file to the server (remembering to keep a backup of the old file), If you check your website now, you should find the error disappears.