I plan to implement some specific content for specific categories only, about 15. I wonder will wordpress conditionals (15 if) slow down my website visibly? Sorry if this sounds silly.
2 Answers
The answer is no but just to put your question into perspective I tried the following code. 1.5 million ifs.
$start = microtime();
$count = 0;
while(true) {
$count++;
if($count > 1500000) {
break;
}
}
$stop = microtime();
$total = $stop-$start;
print "Total time:$total";
0.16 seconds
-
That's not really relevant, he may be calling an expensive function within the IF statement Apr 22, 2012 at 20:49
Conditional Tags are basically just short wrapper functions for parts of the global $wp_query;
.
Example: is_author();
function is_author( $author = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
return false;
}
return $wp_query->is_author( $author );
}
And this ↑ just retrieves a class var from the WP_Query
object. That's it. So: No, they can't really add any noticeable overhead (unless you don't get millions of synchronous hits). Not more than interacting with any other object.