0

My page templates are currently built up as shown in first example but I really don't like that half of the template is just sitting there, not being used and takes the server resources for no good reason.

Does everything in both examples gets parsed by server, emphasis on get_template_part()?


<?php

//Page template

if( $something ) {

    // 1000 lines of code
}
else if( $something_else ) {

    // 1000 lines of code
}

?>

versus


<?php

// Page template

if( $something ) {

    // Template with 1000 lines of code
    get_template_part( 'lib/template', 'option-a' );
}
else if( $something_else ) {

    // Template with 1000 lines of code
    get_template_part( 'lib/template', 'option-b' );
}

?>
1

Only if $something or $something_else are true, otherwise the code will jump to the next argument.

  • I have a feeling you kept executing the code in mind.. How about parsing? I know for sure that the whole code in first example gets parsed, even if it's in false block. How are things with get_template_part() content? – N00b Feb 22 '16 at 7:11
  • 1
    get_template_part is a function – if the function is never run, the code is never executed – Andrew Lazarus Feb 22 '16 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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