[PageSpeedGuide] To get the list of registered css and js add the following code

Posted in: Newspaper
Post count: 38

I get the error:

Fatal error: Call to undefined function add_action() in /home/xxxxx/public_html/wp-includes/functions.php on line 4643

Line 4643 is: add_action( ‘wp_print_scripts’, ‘td_inspect_scripts’ );

If I take that line out, my site starts to work again but I don’t get the list with the id for all the css and js on my WP dashboard.

Please help.

Post count: 9544

That is part of the main WordPress install and not part of the theme, so I’d likely start by turning off your plugins, then turning them back on one by one to see if you still get that error.

You generally do *NOT* want to edit the core WordPress files inside admin, or includes, unless you know what you’re doing.

  • This reply was modified 11 years by simchris.
Post count: 38

Okay… Well I just tried it with ALL the plugins deactivated and it still gives me the fatal error…

I’m simply following your instructions on removing render blocking css/js – using the TagDiv Speed Booster plugin by adding the code :

function td_inspect_scripts() {
global $wp_scripts, $wp_styles;
echo ‘registered scripts<br>’;
foreach ($wp_scripts->queue as $handle) {
echo $handle . ‘ | ‘ . $wp_scripts->registered[$handle]->src . ‘<br>’;
}
echo ‘registered styles<br>’;
foreach ($wp_styles->queue as $handle) {
echo $handle . ‘ | ‘ . $wp_styles->registered[$handle]->src . ‘<br>’;
}
}
add_action( ‘wp_print_scripts’, ‘td_inspect_scripts’ );

into Functions.php as you have stated… And “generally,” I do know what I am doing. I followed your steps to a tea.

Post count: 9544

I never suggested adding that code to the functions.php file, so it might have been somebody else; obviously if it’s causing an error, it doesn’t work. That may have been posted by somebody using the OLD version of the theme and the OLDER version of the Tagdiv Speedbooster plugin, which has been recently updated, so that suggested code may no longer work. hence the error you’re getting.

Anything which tells you to edit core WP code should NEVER be done, in my opinion. “Generally.” But you know what you’re doing, so have at it.

Always check the DATE on any post which suggests changing theme code, in some way, outside of normal wordpress functions such as I use, and line that up with current date/version of theme and plugins. So, if something worked with v1 of a plugin, it might not work with v2 of a plugin, “generally” speaking.

  • This reply was modified 11 years by simchris.
Post count: 38

Okay, well https://forum.tagdiv.com/pagespeed-guide/ is where I got this reference from, and it was suggested by “you” guys. The post date is July 20, 2014 which I would say is fairly new and should still be aplicable as of this date, as I see no reason why it should not be. And I’m sure if you bothered to replicate these steps to see what was wrong, we would be able to come to a conclusion already.

All I want is a fix for this. I’m following “your” guide to achieve removing render blocking css/js – using the TagDiv Speed Booster plugin as set out in: https://forum.tagdiv.com/pagespeed-guide/

I followed your instructions and it did not work. The only line of code that gives me a fatal error is “add_action( ‘wp_print_scripts’, ‘td_inspect_scripts’ );”. And that is also the line of code that enables me to see a list of all the ids for all the css and js (needed for the next step).

So I ask again, please help me get through this step successfully.

Post count: 9544

Sure, if you want to pay me to replicate the steps, would be happy to. “My” guide does not include those steps, as I NEVER edit the core code, and I only use compliant WordPress functions to optimize the functions.php file and well known suggestions for htaccess directives, etc.

I never made those instructions you refer to, so I’m going to pass on any help. Sorry to have offered; I likely only added to the confusion. Sorry about that.

I’m sure one of the other contributors here using that “hack” might be able to help. Likely you will want to post the question in that thread, as the hack you’re looking to do has nothing to do with theme support, or my suggestions for PageSpeed improvement.

Sorry, I can’t be any further help on this topic. Perhaps the person who suggested that hack might be able to help – try posting in that thread for help from those of us contributing suggestions for pagespeed improvements. Maybe the person who posted the hack will follow up for you on what he/she did to use that element you’re trying to use.

And again, the tagdiv speedbooster code and plugin has been updated for September, so the July hack may no longer work. But I’ve already said that, so I’ll stop talking now. 🙂

Post count: 9544

Sorry.
Wait for Lucian or Marius to get in tomorrow.

I think they need to update that code on their docs page you’re referencing, which pulls list of the CSS and JS, which is what you’re looking for.

I don’t work here, just helping people as I’ve been doing webdev since 1994 and using WordPress since it launched in beta.

Post count: 38

Oh okay… Sorry, I appologize for being rude to you. I thought you were someone who “worked” here (maybe with Customer Support), hence my frusteration and confusion at what you were saying at times.

Post count: 1291

Hi,

Please check if you properly added the entire code at the end of the functions.php file – http://screencast.com/t/GSWtbWpFG9G5

If you did and still receive that error please send an email at contact@tagdiv.com, specify the issue and provide wp-admin and ftp access so i can take a look.

Thank you, Emil G.

Viewing 9 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic.