sricks3
sricks3

Reputation: 15

Wordpress: functions.php Breaking Standard WP Functions

This issue is driving me crazy.

This morning, the Wordpress theme I'm creating included a very simple functions.php file, and my site worked properly. Today, I wrote a new function to iterate through categories and list certain posts, and that's the only change I made to functions.php.

After uploading the revised functions file to the server, I get a 500 error every time I access my site. I though, "OK, my new function broke something. I'll just remove it from functions.php and start over." However, after reverting to the original version of the file (the version that worked this morning), I'm still getting the 500 error.

If I remove functions.php from the server, my pages load (without their sidebars obviously, but they load). As soon as I upload the file again (same version that worked this morning), I get the 500 error.

I checked the error log, and I've found that, when I have functions.php on the server, Wordpress (or php more likely) can no longer find the get_template_directory_uri() function. I've done nothing to alter any of the standard Wordpress functions, and this only happens when I've got functions.php uploaded.

What might be causing functions.php to break the standard functions?

Here's my functions.php file:

<?php

/* *********************************************
 * Create left-hand sidebar for single.php
 * 
 * TODO: Finalize $sricks_single_left_sidebar. 
 * ********************************************/
$sricks_single_left_sidebar = array(
    'name'          => 'Left Sidebar',
    'id'            => 'lt-single',
    'description'   => 'This is the sidebar on the left side of the single.php template page.',
    'before_widget' => '<!-- Left-Single Sidebar --><div class="lt-single">',
    'after_widget'  => '</div> <!-- End Left-Single Sidebar -->',
    'before_title'  => '<h1>',
    'after_title'   => '</h1>',
);
register_sidebar( $sricks_single_left_sidebar );

/* *********************************************
 * Create header_search sidebar to be used on
 * all pages
 * ********************************************/
$sricks_header_search_sidebar = array(
    'name'          => 'Header Search',
    'id'            => 'header-search',
    'description'   => 'This is the search box in the page header.',
    'before_widget' => '<!-- Header-Search Sidebar --><div class="header-search">',
    'after_widget'  => '</div> <!-- End Header-Search Sidebar -->',
    'before_title'  => '<h1>',
    'after_title'   => '</h1>',
);
register_sidebar( $sricks_header_search_sidebar );
?>

Upvotes: 0

Views: 491

Answers (2)

sricks3
sricks3

Reputation: 15

Thanks everyone, especially Spencer Cameron. It turns out I forgot the open and close parentheses in my new function's declaration. Wordpress reads functions.php before any of the built-in functions, so it just got stuck there.

When I submitted my code, I left out my new function because I had deleted everything from the body of the function; what could go wrong? Lesson learned...

Upvotes: 1

Spencer Cameron-Morin
Spencer Cameron-Morin

Reputation: 1430

To find the cause of issues in WordPress when you get 500 level errors, a blank white screen, or any other strange or unexpected behavior, define the WP_DEBUG constant in wp-config.php.

Like this:

define( 'WP_DEBUG', true );

If you're developing or making changes to a site, it's usually a good idea to enable this feature until you're done editing. It can make it very easy to spot and correct mistakes that could otherwise vex for hours.

Upvotes: 2

Related Questions