I’ve just moved one of my WordPress blogs over to a new server that has PHP 7 on. Unfortunately I’m getting a TON of errors (the page is just blank)

Running index.php via SSH, I get:

PHP Parse error:  syntax error, unexpected 'add_action' (T_STRING), expecting function (T_FUNCTION) in /home/rachel/web/mysite.co.uk/public_html/wp-content/themes/custom-theme/functions.php on line 570

Line 570 is:

add_action('wp_enqueue_scripts', 'qns_load_js');

The full code is:

add_action('wp_enqueue_scripts', 'qns_load_js');

if( ! function_exists( 'qns_load_js' ) ) {

    function qns_load_js() {



        if ( is_admin() ) {
        } else {

            // Load JS

            wp_register_script( 'jquery_ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', array( 'jquery' ), '1.8', true );
            wp_register_script( 'custom', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '1', true );
            wp_enqueue_script( array( 'jquery_ui', 'hoverintent', 'superfish', 'prettyphoto', 'flexslider', 'custom' ) );

            global $is_IE;

            if( $is_IE ) wp_enqueue_script( 'selectivizr' );

            if( is_single() ) wp_enqueue_script( 'comment-reply' );

        }

    }

} 

I found a SO post where they said it was due to the fact anonymous functions are now needed. From what I understood, he suggested changing it to something like:

add_action('wp_enqueue_scripts', function() {

        if ( is_admin() ) {
        } else {

            // Load JS

            wp_register_script( 'jquery_ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', array( 'jquery' ), '1.8', true );
            wp_register_script( 'custom', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '1', true );
            wp_enqueue_script( array( 'jquery_ui', 'hoverintent', 'superfish', 'prettyphoto', 'flexslider', 'custom' ) );

            global $is_IE;
            if( $is_IE ) wp_enqueue_script( 'selectivizr' );
            if( is_single() ) wp_enqueue_script( 'comment-reply' );
        }
    });

Unfortunately I’m a Perl programmer, so this is a bit out of my area of expertise. Anyone got some tips? The theme developer has also done a disappearing act, so I can’t even get an updated version from her.

Read more here: unexpected ‘add_action’ (T_STRING), expecting function (T_FUNCTION) error since upgrading to PHP7


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: