WordPress.org

Forums

[resolved] How Do i make a child functions.php file without getting an error (4 posts)

  1. Michael Burke
    Member
    Posted 1 year ago #

    i am try to make sure i dont lose modifications to functions.php if i get a theme update but i cant figure out what i have to do because the child one goes before the parent right?

  2. Craig Ralston
    Member
    Posted 1 year ago #

    Try following the steps outlined in the codex: https://codex.wordpress.org/Child_Themes

    Keep in mind - A style.css in your child theme is required to tell WordPress that this is in fact, a child theme.

    If you have already got that far and still are seeing issues, let me know.

  3. esmi
    Forum Moderator
    Posted 1 year ago #

    The child's function.php file always starts off empty - then you add just the new or customised functions to it.

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    what i have to do because the child one goes before the parent

    consider to add the functions, which have to start after the parent theme's ones, by using the 'after_setup_theme' action.

    https://codex.wordpress.org/Plugin_API/Action_Reference/after_setup_theme

    example - adding a new widget area to a child theme:

    add_action( 'after_setup_theme', 'twentytwelvechild_setup' );
    
    function twentytwelvechild_setup() {
    add_action( 'widgets_init', 'twentytwelvechild_widgets_init' );
    }
    
    function twentytwelvechild_widgets_init() {
    	register_sidebar( array(
    		'name' => __( 'Custom Sidebar', 'twentytwelve' ),
    		'id' => 'sidebar-4',
    		'description' => __( 'Appears on Custom page', 'twentytwelve' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => '</aside>',
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
    	) );
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags