WordPress.org

Support

Support » How-To and Troubleshooting » Line breaks in functions.php

Line breaks in functions.php

  • Just a question…

    Why is it that adding a line break of space between a closing php tag and the following opening php tag break WordPress?

    ex:

    ... ?>
    <?php ...

    WordPress is hunky dory.

    ... ?>
    
    <?php ...

    WordPress decides to leave a drinking/dippy bird at the keyboard for the day.

Viewing 4 replies - 1 through 4 (of 4 total)
  • you actually shouldn’t be opening and closing php like that at all in functions.php…..

    just continue on the code….. introducing whitespace between functions will break WP but really there is no need to close and open

    <?php
    function .... code
    ?>
    <?php
    function .... code
    ?>

    should just be

    <?php
    function .... code
    
    function .... code

    There should really just be the opening php tag at the top of functions.php, and then all of your functions added in.

    The only time to close out php is to break out into html if necessary, and then reopen php….

    Well, yea. I realize that now. I was just doing that for cleanliness for my own sanity.

    Some plugins that modify the functions.php file will do something like the following

    <?php
    function some_function(){
        if(){...
        }
    ?>
    <?php }
    function something_else(){...

    It’s a mess, really.

    You have plugins that modify your functions.php file? I’ve never run into one of those before, crazy….

    for code clenliness, I usually use spacing and commenting in my functions.php, whitespace is fine inside of php… so to use your example….

    <?php
    // I ADDED THIS TO DO SOMETHING REALLY COOL
    function some_function(){
        if(){...
        }
    }
    
    // THIS DOES SOMETHING EVEN COOLER!
    function something_else(){...

    But, if you have plugins adding things to your functions.php, that would be unpredictable for sure!

    Yea, embarrassing eh? One is a feedburner plugin and it looks like the other is a WP Related Posts plugin. Those two combined make up for over 1k lines of coded in functions.php.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Line breaks in functions.php’ is closed to new replies.
Skip to toolbar