My site crashed when I added a code from sitepoint to my theme's functions.php file


I’m an avid fan of sitepoint eBooks. I recently purchased “The
Wordpress Anthology” and was very keen to go through with this ebook.

Ok. So far so good. Everything was ok until I hit chapter 4 about Post Types.

I followed the instructions carefully as I was trying out the php
codes on my live site which I’m using to go through with this book.

According to the book’s instructions, I needed to paste the following
codes into my theme’s functions.php file. And I did that rightly. I
went to my theme editor and opened up the functions.php via my
wordpress panel. And pasted this code which was provided by sitepoint.

function check_current_screen() {
if( !is_admin() ) return;
global $current_screen;
print_r( $current_screen );
//add_action( ‘admin_notices’, ‘check_current_screen’ );

function conference_contextual_help() {

      $editspeaker = "From this screen, you can view and update all

your conference’s
$addspeaker = “Enter the details of a new speaker…”;

      $editsession = "View and edit your conference's sessions...";
      $addsession = "Add a new session ...";

      $editsessiontopics = "Add and edit topics...";

      add_contextual_help('edit-conference_speaker', $editspeaker);
      add_contextual_help('conference_speaker', $addspeaker);

      add_contextual_help('edit-conference_session', $editsession);
      add_contextual_help('conference_session', $addsession);

      add_contextual_help('edit-conference_topics', $editsessiontopics);


add_action(‘admin_init’, ‘conference_contextual_help’);

After updating this file, my site kind of crashed giving this error message:

Fatal error: Cannot redeclare check_current_screen() (previously declared in
/home/uawrsp/public_html/wp-content/plugins/sitepoint-custom-types.php:198) in
/home/uawrsp/public_html/wp-content/themes/Chameleon/functions.php on line 317

I’m not sure what went wrong and I even deleted this whole code and
saved the file again, but to no avail. In the end I’ve got to email my
host and told them to rectify my problem which they did.

But I was disappointed in the end that this happened. Right now I’m
too nervous to touch any php files within my wordpress system

Can someone tell me what actually went wrong? :frowning:

You need to have a live environment to try out the instructions on this ebook. How else can I try out without the need to worry about messing up any of the php files?

Thank You.



Welcome to the forum.

Robin my C++ lecturer always used to say “read the error messages”.

According to your error message your script already has a function called check_current_screen() and only one is allowed.

Try renaming one of the functions tp XXX_check_current_screen() and see if that cures your current problem.

Fatal error: Cannot redeclare check_current_screen() (previously declared in
/home/uawrsp/public_html/wp-content/plugins/sitepoint-custom-types.php:198) in
/home/uawrsp/public_html/wp-content/themes/Chameleon/functions.php on line 317