When checking get_defined_vars() on an empty template file my theme loads over 70000 lines of output. Before even including elements on a page all of this is loaded.

  1. Is this correct?
  2. Is there any way to reduce it or remove unnecessary variables?
  3. Do all wp_rewrite rules have to be available for every page load?

2 s
2

Your installation might be … less than optimal.

Using my Mini Theme, no plugins and the following code on the front page right after the opening body tag …

print count( $GLOBALS ) . ' $GLOBALS<br>';
print @count( get_defined_vars(), 1 ) . ' variables<br>';
print count( get_defined_constants( TRUE )['user'] ) . ' constants';

… I get:

 158 $GLOBALS
9759 variables
  85 constants

Still too much for my taste. Keep in mind many plugin and theme developers forget to keep the global namespace clean. Depending on the quality of the addons you have installed your results might be much higher.

And yes, you need those rewrite rules. Some slugs are translated, and translation can change on each request. So they have to be always available.

Leave a Reply

Your email address will not be published. Required fields are marked *