WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How Do i make a child functions.php file without getting an error

[Resolved] How Do i make a child functions.php file without getting an error

  • 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Craig Ralston
    Participant

    @craig-ralston

    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.

    esmi
    Forum Moderator

    @esmi

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

    Michael
    Forum Moderator

    @alchymyth

    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>',
    	) );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] How Do i make a child functions.php file without getting an error’ is closed to new replies.