• I went to add a function on my functions.php file and I got the error below. I then removed the function and wound up going to a clean functions.php file I had saved and pasting the code from there and I’m STILL getting the same error. How do I fix this?

    Parse error: syntax error, unexpected ‘add_action’ (T_STRING), expecting function (T_FUNCTION) in /home1/ikelove/public_html/wp-content/themes/inove/functions.php on line 10

    [ Moderator note: please use pastebin.com for posting large blocks of code. ]

Viewing 10 replies - 1 through 10 (of 10 total)
  • That error means that on line 10 of your theme’s functions.php, there is an add_action() function that is being called within the class, but it’s not wrapped in a function. It’s possible that a curly bracket { is missing somewhere: See https://wordpress.org/support/topic/add_action-always-resulting-in-unexpected-t_string?replies=16 for a potentially similar issue.

    If you can’t find the missing bracket, reinstalling the theme (https://wordpress.org/themes/inove) should fix the error. **Remember: Any changes made to theme files would be overwritten. WordPress suggests saving changes in Child Themes to prevent those changes from being lost during a theme upgrade.

    Thread Starter ikelove

    (@ikelove)

    Hey, thanks for your generosity in responding.
    In any case, Good Lord, re-installing inove was the last thing I wanted to do. I had saved the files some years back in case something like this happened, so I wonder why when I cut and pasted the code from the original I saved that I’m still getting this error.

    I found the add_action function at your suggestion but everything there looks fine, do you see anything that’s missing?

    // register functions
    add_action('admin_menu', array('iNoveOptions', 'add'));
    
    /** l10n */
    function theme_init(){
    	load_theme_textdomain('inove', get_template_directory() . '/languages');
    }
    add_action ('init', 'theme_init');

    If you haven’t made any other changes to the theme files, and if you have FTP access, the easiest way to reset the theme code would be to delete the site via FTP (**not through the admin panel**), and then download it from https://wordpress.org/themes/inove and paste the theme back in.

    Looking at line 10: http://pastebin.com/5772NM9S I don’t see what could be causing the issue. It looks like the add_action statements are working, as well.

    There are a lot of potential things that could be causing the problem. If you can’t reinstall the theme, try various solutions like:

    1. Looking for a missing apostrophe, quotation mark, curly braces, etc. You might try running it through http://phpcodechecker.com/ to see if you find errors.
    2. Switch to a default theme (Twenty-*) and see if the error still occurs.
    3. Deactivating plugins to see if you’re still finding the error.

    Barring plugin or theme conflicts, and properly formatted PHP, it might be wise to contact the theme developer about a solution.

    Thread Starter ikelove

    (@ikelove)

    If I switch to the default theme, would I lose all the changes made to the inove theme?

    It’s very strange how all this happened. All was good until I simply went on functions.php and added this line of code on the top right below “class inoveOptions (” in order to get my default page to show only one category of posts and that’s when I started getting the error. I removed the code and I still got the same error.

    function my_home_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '1' );
        }
    }
    add_action( 'pre_get_posts', 'my_home_category' );

    If you switch to the default theme, the settings should all return once you reactivate it. Those settings are stored in the database and won’t be removed unless a theme is deactivated and deleted in the backend.

    The problem could have been a result of the “add_action” statement being located within the iNoveOptions class. Try adding it in above the class iNoveOptions like this:

    <?php
    
    function my_home_category( $query ) {
    	if ( $query->is_home() && $query->is_main_query() ) {
    		$query->set( 'cat', '1' );
    	}
    }
    add_action( 'pre_get_posts', 'my_home_category' );
    
    /** inove options */
    class iNoveOptions {
    
    	public static function getOptions() {
    		$options = get_option( 'inove_options' );
    		if ( ! is_array( $options ) ) {
    			$options['google_cse']           = false;
    			$options['google_cse_cx']        = '';
    Thread Starter ikelove

    (@ikelove)

    Nope, doesn’t work. I still get the same error. Funny how everything changed when I added that code and then removed it. I was even given a link to the most updated function.php code here: https://themes.svn.wordpress.org/inove/3.0.5/functions.php and I still get that same line of error which is weird because I touched no other .php file.

    Thread Starter ikelove

    (@ikelove)

    An added problem is that now with this error, it won’t even let me go to another part of the back-end to switch to another theme.

    Navigate to /wp-content/themes/ and rename the directory of the theme. This will force the default theme to activate.

    Thread Starter ikelove

    (@ikelove)

    You mean on my ftp program I do this? Because I can’t even access the other themes, I don’t even know what to rename the directory of the theme to. Please can you briefly outline the steps.
    Also, now because of this error, I can’t even log out or do anything else.

    This totally sucks.

    Yes, through FTP. Navigating to wp-content/themes/ and changing the name of the directory ( Even by just adding ‘-old’ to the directory name) will deactivate the theme. Theme settings will still remain and will reactivate when the name of the directory is changed back.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘How do I fix: Parse error: syntax error, unexpected 'add_action' (T_STRING), ??’ is closed to new replies.