WordPress.org

Ready to get started?Download WordPress

Forums

Line breaks in functions.php (5 posts)

  1. nickgassmann
    Member
    Posted 2 years ago #

    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.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    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....

  3. nickgassmann
    Member
    Posted 2 years ago #

    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.

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    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!

  5. nickgassmann
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.