Why Is My If Statement Crashing WordPress?

I’m an experienced web developer, so I’m embarrassed to ask this, but why is my if statement cashing WordPress?

<!-- THE BLOCK FOR THE HEADER IN THE CMS !-->
<span class="PostHeader"><p>
<?php

    if(empty(get_the_block("Header"))){
        echo "Employment"; //Empty only on the employment screen
    } else {
        the_block("Header");
    }

?>
</p>
<!-- END OF THE BLOCK -->

This is in a template for WordPress, and if I comment out the control structure, it loads fine, but as soon as I try to let it run in the template, the page just stops loading.

Read More

Why is it doing this?

–EDIT–

Sorry forgot to mention that the “Multiple Content Blocks” Plugin is enabled.

Related posts

Leave a Reply

3 comments

  1. empty() is a structure not a function, it only accepts variables, you should use this instead:

    <!-- THE BLOCK FOR THE HEADER IN THE CMS !-->
    <span class="PostHeader"><p>
    <?php
    
        $block = get_the_block("Header");
    
        if(empty($block)){
            echo "Employment"; //Empty only on the employment screen
        } else {
            the_block("Header");
        }
    
    ?>
    </p>
    <!-- END OF THE BLOCK -->
    

    For further informations see PHP Empty

  2. You must download this plugin : http://downloads.wordpress.org/plugin/multiple-content-blocks.zip and install it.

    The function you try to use aren’t in the WordPress Codex and are also not found. That’s why you get a blank page aka the white screen of death (also because php reporting_error is set to false). You can try to put this line

    error_reporting(-1);
    

    in front of your if else statement.

    Material :

    http://plugins.trendwerk.nl/documentation/multiple-content-blocks/