Optimizing functions.php
-
Am I thinking right that several functions that are specific to WP page types would be more optimally enclosed in a conditional in functions.php, instead of the server having to evaluate several functions for every page that end up only doing something for another page type via a conditional inside the functions? Specifically I have several functions for AMP pages and several for non-AMP pages.
I never see this suggested. Am I missing something on why this would not be optimal? Or would the performance difference with this amount of code be so tiny that it wouldn’t register in any Pagespeed Insights metric?
My functions.php is 12KB, and an include file I need for AMP pages is 57KB.
Here’s what I have in mind:
if (function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint()) { // Page is AMP. Apply several filters, actions, and an include: include('simple_html_dom.php'); add_filter( 'the_content', 'amp_filter' ); function amp_filter( $content ) { /* code */ } add_action('avada_before_body_content','gtm_body_code', 1); function gtm_body_code() { /* code */ } // etc } else { // several non-AMP functions here }
The topic ‘Optimizing functions.php’ is closed to new replies.