WordPress.org

Forums

Twenty Fourteen
functions.php child theme (13 posts)

  1. johanna2patricia
    Member
    Posted 11 months ago #

    Hi everybody,
    I want to create a functions.php for my child theme.
    But I can't seem to get it right. I get an error.
    This is what I want in the functions.php:

    function twentyfourteen_widgets_init() {
    	require get_template_directory() . '/inc/widgets.php';
    	register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
    
    	register_sidebar( array(
    		'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
    		'id'            => 'sidebar-1',
    		'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    	register_sidebar( array(
    		'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
    		'id'            => 'sidebar-2',
    		'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    	register_sidebar( array(
    		'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
    		'id'            => 'sidebar-3',
    		'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    }
    add_action( 'widgets_init', 'twentyfourteen_widgets_init' );

    And this:

    function alter_comments_form_defaults($default) {
        unset($default['comment_notes_after']);
        return $default;
    }
    add_filter('comment_form_defaults','alter_comments_form_defaults');

    How exactly should the functions.php look like then?

    Johanna

  2. Naziman
    Member
    Posted 11 months ago #

    Is it your blog became white blank screen? Then i think you forgot to put opening <?php and closing ?>.

    Sincerely,
    [sig moderated as per the Forum Rules]

  3. johanna2patricia
    Member
    Posted 11 months ago #

    Hi Naziman,
    No I get an error.
    Maybe you can help me to put the above code in a functions.php?

    Johanna

  4. esmi
    Forum Moderator
    Posted 11 months ago #

    Try checking your site's error logs for a more specific error message. Your hosts should be able to help you accessing your site's error logs.

  5. johanna2patricia
    Member
    Posted 11 months ago #

    Hi Esmi,
    It has nothing to do with my host.
    I just have a wrong functions.php in my child theme.
    I get an error that says that something is declared twice.
    I understand the message, but I don't know how to create this functions.php for my child theme.
    I have now changed the functions.php from the original theme, but I know that isn't handy in case the Twenty Fourteen theme is updated.
    So all that I am looking for is somebody that can tell me how I create that functions.php for my child theme with the above codes.

    Johanna

  6. esmi
    Forum Moderator
    Posted 11 months ago #

    It has nothing to do with my host.

    I didn't say it had something to do with your hosts. But all sites have error logs. They are what you use when you get a blank screen and need to know what & where the error is. Try checking yours.

  7. johanna2patricia
    Member
    Posted 11 months ago #

    The error is like I said, that something is declared twice: "Fatal error: Cannot redeclare twentyfourteen_widgets_init() (previously declared in /data/home/secr02/domains/secretsistersblog.com/public_html/wp-content/themes/twentyfourteen-child/functions.php:9) in /data/home/secr02/domains/secretsistersblog.com/public_html/wp-content/themes/twentyfourteen/functions.php on line 197"

    This is the functions.php:

    <?php
    function alter_comments_form_defaults($default) {
        unset($default['comment_notes_after']);
        return $default;
    }
    add_filter('comment_form_defaults','alter_comments_form_defaults');
    
    function twentyfourteen_widgets_init() {
    	require get_template_directory() . '/inc/widgets.php';
    	register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
    
    	register_sidebar( array(
    		'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
    		'id'            => 'sidebar-1',
    		'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    	register_sidebar( array(
    		'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
    		'id'            => 'sidebar-2',
    		'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    	register_sidebar( array(
    		'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
    		'id'            => 'sidebar-3',
    		'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget'  => '</aside>',
    		'before_title'  => '<h2 class="widget-title">',
    		'after_title'   => '</h2>',
    	) );
    }
    add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
    
    ?>

    The first part works, but when I add the second part, then I get the error. I want to change the original h1 to h2.
    Somebody any idea what is wrong in the above child functions.php?

    Johanna

  8. esmi
    Forum Moderator
    Posted 11 months ago #

    Try changing the name of the the twentyfourteen_widgets_init() function.

  9. johanna2patricia
    Member
    Posted 11 months ago #

    What name exactly?
    widgets_init? For example to widgets_init-child?

  10. esmi
    Forum Moderator
    Posted 11 months ago #

    Yes - that should do it.

  11. johanna2patricia
    Member
    Posted 11 months ago #

    No that doesn't do it. The same error.
    If I change this: function twentyfourteen_widgets_init() to function twentyfourteen_widgets_init-child()
    I get an error.
    The same if I change these 2: add_action( 'widgets_init', 'twentyfourteen_widgets_init' );

  12. johanna2patricia
    Member
    Posted 11 months ago #

    I searched online and I think I first have to perform a remove action syntax. But I have no idea how to do that.
    Is there maybe somebody that is good with php here?
    Thanks.

    Johanna

  13. Tche111
    Member
    Posted 9 months ago #

    Hello Johanna,
    I think I encountered the same problem while developping my new website on wamp-local server. I can not show you the result but it works great. How did I do to add various widgetizable zones in 2014-footer?
    I added this in the functions.php of twentyfourteen-child (without touching to the parent):

    <?php
    if ( function_exists('register_sidebar') ) {
     register_sidebar( array(
      'name' => __( 'First Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-4',
      'description' => __( 'First footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
    
    register_sidebar( array(
      'name' => __( 'Second Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-5',
      'description' => __( 'Second footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
    
    register_sidebar( array(
      'name' => __( 'Third Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-6',
      'description' => __( 'The third footer widget area',  'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
    
    register_sidebar( array(
      'name' => __( 'Fourth Footer Widget Area', 'twentyfourteen' ),
      'id' => 'sidebar-7',
      'description' => __( 'The fourth footer widget area', 'twentyfourteen' ),
      'before_widget' => '<div class="textwidget">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
     ) );
    }
    ?>

    Actually this is creating 4 new zones... That are not yet included in footer.php nor in sidebar-footer.php. In fact, I created a copy of sidebar-footer.php, named it sidebar-footer2.php and I adapted it as follows:

    <?php
    
    /**
    
     * The Footer widget areas.
    
     *
    
     * @package Cryout Creations
    
     * @subpackage mantra
    
     * @since mantra 0.5
    
     */
    
    ?>
    <div class="footline">
    <div class="sidefoot">
       <ul>
          <?php
          if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-4') ) :
          endif; ?>
       </ul>
    </div>
    <div class="sidefoot">
       <ul>
          <?php
          if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-5') ) :
          endif; ?>
       </ul>
    </div>
    <div class="sidefoot">
       <ul>
          <?php
          if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-6') ) :
          endif; ?>
       </ul>
    </div>
    <div class="sidefoot">
       <ul>
          <?php
          if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-7') ) :
          endif; ?>
       </ul>
    </div>
    </div>

    (Note that I created two new div to set up the new widget zones.)
    Last action consist in calling this new sidebar-footer2 in footer.php.
    Just put a copy of footer.php in your child theme and replace
    <?php get_sidebar( 'footer' ); ?>
    by
    <?php get_sidebar( 'footer2' ); ?>
    This should help you but tell me if it doesn't...
    T'Cheers

Reply

You must log in to post.

About this Theme

About this Topic