WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding a new widget to a Child Theme's functions.php (3 posts)

  1. niallolaoghaire
    Member
    Posted 1 year ago #

    Hi
    I can get the new widget to work in the parent theme's (I'm using Responsive) functions.php
    but when I make a new functions.php file in the child theme with

    <?php
        function responsive_widgets_init() {
    	register_sidebar(array(
                'name' => __('Home Top Image', 'responsive'),
                'description' => __('Area 12 - home-top-image.php', 'responsive'),
                'id' => 'home-top-image',
                'before_title' => '<div class="widget-title">',
                'after_title' => '</div>',
                'before_widget' => '<div id="%1$s" class="%2$s">',
                'after_widget' => '</div>'
            ));
        }
        add_action('widgets_init', 'responsive_widgets_init');
    ?>

    I get an error message in my browser: Fatal error: Cannot redeclare responsive_widgets_init() (previously declared in /home/c1944495/public_html/xxxlarrysxxx/wp-content/themes/child_of_responsive/functions.php:9) in /home/c1944495/public_html/xxxlarrysxxx/wp-content/themes/responsive/includes/functions.php on line 18

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    simply use a differnt function name;

    instead:
    'responsive_widgets_init'
    use for example:
    'responsivechild_widgets_init'

    and the same here:
    function responsivechild_widgets_init() {

  3. niallolaoghaire
    Member
    Posted 1 year ago #

    Ah, thank you kind sir, that worked!

Topic Closed

This topic has been closed to new replies.

About this Topic