WordPress.org

Forums

[resolved] [Twenty 11] WSoD caused by this code (13 posts)

  1. cinnoi
    Member
    Posted 2 years ago #

    I have the white screen of death whenever logging in, updating a post, or saving an edit. I've narrowed down the source of the problem to this code (it's not long):

    Here (Pastebin)

    However, I've no idea what may be wrong with the code (I'm a WP noob).

    Any help would be greatly appreciated.

    P.s. I'm using a child theme and that will be the only code in the function.php file (along with a bit lowering header size).

  2. Good Guy
    Member
    Posted 2 years ago #

    What have you got at that link? I am getting this message on my system:

    http://tinyurl.com/7todzhq

  3. cinnoi
    Member
    Posted 2 years ago #

    Well, I certainly don't get that.

    Here's the code:

    <?php
    // ADD SIDEBAR
    add_filter('body_class', 'fix_body_class_for_sidebar', 20, 2);
    function fix_body_class_for_sidebar($wp_classes, $extra_classes) {
        if( is_single() || is_page() ){
           if (in_array('singular',$wp_classes)){
                foreach($wp_classes as $key => $value) {
                    if ($value == 'singular')
                        unset($wp_classes[$key]);
                }
            }
        }
    
         return array_merge($wp_classes, (array) $extra_classes);
    }
    ?>
  4. esmi
    Forum Moderator
    Posted 2 years ago #

    What is it that you are trying to do?

  5. cinnoi
    Member
    Posted 2 years ago #

    This code is causing the white screen of death whenever I update a page or save any changes on my dashboard. If I remove the code, everything works perfectly. I'm wondering if there's something wrong with the code itself.

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    I think that's a given :-)

  7. cinnoi
    Member
    Posted 2 years ago #

    Ha, yeah. I just have no idea what I'm doing and I'm new to coding, so I was just wondering if anyone on here sees something glaringly wrong in the code (which might be causing the WSoD).

    Unfortunately, when it comes to reading code I'm about as useful as Stevie Wonder.

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    What is it that you are trying to do?

  9. cinnoi
    Member
    Posted 2 years ago #

    Well, I want to add a sidebar onto regular posts in twenty eleven. I found this code on a random website I found on google (I know, but for a newbie they're a godsend).

    The author of the guide said to paste the above code into the child theme's function.php and <?php get_sidebar(); ?> just above <?php get_footer(); ?> in the page.php and single.php.

    So, I copied page.php and single.php from the parent theme and put the copies in my child theme folder. I then followed the above instructions. And now I have the WSoD.

    In case it might help, here's the website.

  10. esmi
    Forum Moderator
    Posted 2 years ago #

    I found this code on a random website I found on google

    That's never a good idea if you don't know any PHP yourself. That code you posted above will not do anything to add a sidebar to a theme. Also, you should never edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. Instead create a child theme for your changes.

    If you just want to add a sidebar, have a look at http://wordpress.org/extend/plugins/twenty-eleven-theme-extensions/

  11. cinnoi
    Member
    Posted 2 years ago #

    I did it all in a child theme, so I was well behaved on that point. But thanks for the link. Now to delete the code. Cheers for the help!

  12. esmi
    Forum Moderator
    Posted 2 years ago #

    If you already have a child theme, you could also look at creating a custom version of single.php in your child theme - complete with sidebar.

  13. cinnoi
    Member
    Posted 2 years ago #

    Cool, I've no idea how to do that so I think I'll stick to the extension (rather than using google for some dodgy codes).

Topic Closed

This topic has been closed to new replies.

About this Topic