• Hi there

    I’m getting this message:

    Fatal error: Cannot redeclare omega_theme_setup() (previously declared in /home4/pmcg911/public_html/bibliophone.com/wp-content/themes/omega-child/functions.php:16) in /home4/pmcg911/public_html/bibliophone.com/wp-content/themes/omega/functions.php on line 77

    when I enter this code into my child theme functions.php file:

    remove_action( 'omega_before_header', 'omega_get_primary_menu' );
            add_action( 'omega_after_header', 'omega_get_primary_menu' );

    In fact I get some kind of fatal error every time I try to make changes to the functions file. My functions.php file looks like this:

    <?php
    /* Load Omega theme framework. */
    require ( trailingslashit( get_template_directory() ) . 'lib/framework.php' );
    new Omega();
    
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which runs
     * before the init hook. The init hook is too late for some features, such as indicating
     * support post thumbnails.
     */
    function omega_theme_setup() {
    
    	/* Load omega functions */
    	require get_template_directory() . '/lib/hooks.php';
    
            remove_action( 'omega_before_header', 'omega_get_primary_menu' );
            add_action( 'omega_after_header', 'omega_get_primary_menu' );
    
    	/* The best thumbnail/image script ever. */
    	add_theme_support( 'get-the-image' );
    
    	/* Load scripts. */
    	add_theme_support(
    		'omega-scripts',
    		array( 'comment-reply' )
    	);
    
    	add_theme_support( 'omega-theme-settings' );
    
    	add_theme_support( 'omega-content-archives' );
    
    	/* Enable custom template hierarchy. */
    	//add_theme_support( 'omega-template-hierarchy' );
    
    	/* Enable theme layouts (need to add stylesheet support). */
    	add_theme_support(
    		'theme-layouts',
    		array(
    			'1c'        => __( 'Content',           'omega' ),
    			'2c-l'      => __( 'Content / Sidebar', 'omega' ),
    			'2c-r'      => __( 'Sidebar / Content', 'omega' )
    		),
    		array( 'default' => is_rtl() ? '2c-r' :'2c-l', 'customize' => true )
    	);
    
    	/* implement editor styling, so as to make the editor content match the resulting post output in the theme. */
    	add_editor_style();
    
    	/* Support pagination instead of prev/next links. */
    	add_theme_support( 'loop-pagination' );	
    
    	/* Better captions for themes to style. */
    	add_theme_support( 'cleaner-caption' );
    
    	/* Add default posts and comments RSS feed links to <head>.  */
    	add_theme_support( 'automatic-feed-links' );
    
    	/* Enable wraps */
    	add_theme_support( 'omega-wraps' );
    
    	/* Enable custom post */
    	add_theme_support( 'omega-custom-post' );
    
    	/* Enable custom css */
    	add_theme_support( 'omega-custom-css' );
    
    	/* Enable custom logo */
    	add_theme_support( 'omega-custom-logo' );
    
    	/* Enable child themes page */
    	add_theme_support( 'omega-child-page' );
    
    	/* Handle content width for embeds and images. */
    	omega_set_content_width( 640 );
    
    }
    
    add_action( 'after_setup_theme', 'omega_theme_setup' );

    (that’s with the new code added)

    Am I doing something wrong? I often find that if I try to change something in my child theme, it doesn’t get overriden.

    Thanks for your help

    Paul

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter paulmc911

    (@paulmc911)

    Sorry my site is https://www.bibliophone.com

    Thanks

    Look at what the error message is telling you:

    Cannot redeclare omega_theme_setup()

    /home4/pmcg911/public_html/bibliophone.com/wp-content/themes/omega-child/functions.php on line 16)

    /home4/pmcg911/public_html/bibliophone.com/wp-content/themes/omega/functions.php on line 77

    What you’ve done is re-declare the same function name in the child theme as one in the parent theme, and that doesn’t work. All functions have to have individual names. What you’ll need to do is either remove your new function, or change the name of it so that it isn’t the same as the existing one.

    Thread Starter paulmc911

    (@paulmc911)

    Ah so what if I put

    function omega_child_theme_setup () {

    at the start and then entered the function. By calling is omega_child_theme_setup rather that omega_theme_setup, would that do the trick??

    As long as the function names are unique it will work. ??

    Thread Starter paulmc911

    (@paulmc911)

    Ok so I tried that, but then instead of getting the fatal error message, I got a syntax message regarding the term ‘require’ on this line:

    /* Load omega functions */
    require get_template_directory() . ‘/lib/hooks.php’;

    Any clues as to why that might be? I haven’t changed that line at all and it’s just as it appears in the parent theme’s functions.php, so not sure why it isn’t liked all of a sudden in my child theme.

    Thanks for your help on this,

    Paul

    There’s nothing wrong with that line… but it could be with the file that you’re require()‘ing.

    You know that you only have to do that once, and it will be fine? You don’t need to copy things like that from the parent theme.

    Thread Starter paulmc911

    (@paulmc911)

    Yes, I have read up on child themes and I thought I understood them but clearly not entirely! Sorry to be so basic here, but if I create a functions.php in my child theme then, and it just contains the following:

    <?php
    /* Load Omega theme framework. */
    require ( trailingslashit( get_template_directory() ) . 'lib/framework.php' );
    new Omega();
    
    /**
     * Sets up theme defaults and registers support for various WordPress features.
     *
     * Note that this function is hooked into the after_setup_theme hook, which runs
     * before the init hook. The init hook is too late for some features, such as indicating
     * support post thumbnails.
     */
    function omega_child_theme_setup() {
    
            remove_action( 'omega_before_header', 'omega_get_primary_menu' );
            add_action( 'omega_after_header', 'omega_get_primary_menu' );

    …will that work? Do I need to close it off with a ‘}’ and secondly, is it ok to leave this code out of my child theme functions.php:

    /* Load omega functions */
    	require get_template_directory() . '/lib/hooks.php';

    Thanks again

    Paul

    Anything that’s in your main themes functions.php file does not need to be added to your child theme’s functions.php file. That only creates the problem you had from the start again.

    When you’re writing functions, they always need a closing }, no matter what. Otherwise you’ll get parse errors on your code, and it will break.

    Thread Starter paulmc911

    (@paulmc911)

    Ok so my child theme functions.php could just be this:

    <?php
    
    function omega_child_theme_setup() {
    
            remove_action( 'omega_before_header', 'omega_get_primary_menu' );
            add_action( 'omega_after_header', 'omega_get_primary_menu' );
    }

    and that should work?

    Thanks a lot

    Thread Starter paulmc911

    (@paulmc911)

    I don’t need a closing tag, right? Just the opening ‘<?php’

    Thread Starter paulmc911

    (@paulmc911)

    So I added that to my child theme as functions.php but now I get this message when I try to log into my admin site:

    Parse error: syntax error, unexpected ‘}’ in /home4/pmcg911/public_html/bibliophone.com/wp-content/themes/omega-child/functions.php on line 8

    For some reason it doesn’t like the closing } at all! Have I put it in the right place? Should I leave a line break or two?

    Thanks for your help with this.

    Paul

    What you’ve got there is only 7 lines, so there must be something else on line 8 that you haven’t shown on here.

    Thread Starter paulmc911

    (@paulmc911)

    You’re right, I’ve copied the doc, not the actual file uploaded to my FTP. But – the only difference is a line with nothing in it at all underneath the add_action line and above the }. So including that blank line, there are 8 lines and the } is indeed on the 8th line.

    There’s nothing in that bit of code that’s wrong or out of place so the error isn’t with that part. Normally that owuld mean that there’s something different in your file then there is in what you’ve pasted in there. Just as a question, what program are you using to edit your files?

    Thread Starter paulmc911

    (@paulmc911)

    I use notepad and then upload to hostgator cpanel. That has an edit facility where you can edit as plain text or as code, and I use the code editor.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Fatal error: Cannot redeclare’ is closed to new replies.