0

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.

1
  • Can you edit your question to elaborate a little more? What type of content? Is it from your Wordpress site? Is it from another website? The more details, the better. Apr 22, 2012 at 17:19

2 Answers 2

1

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

1
  • That's not really relevant, he may be calling an expensive function within the IF statement Apr 22, 2012 at 20:49
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.