Site logo

Archived topic

3 new widgets (page-new.php)

5 replies · Started by Jean Paiva on December 15, 2014

Viewing posts 1–6 of 6

Hey Tom, I'm stuck in something here. (I'm using child theme)

I need to create 3 widgets area after header so I created a new page (page-homepage.php) and I call the new widgets:

<div class="grid-container">
		<div class="grid-33"><?php dynamic_sidebar( 'left-top' ); ?></div>
		<div class="grid-33"><?php dynamic_sidebar( 'mid-top' ); ?></div>
		<div class="grid-33"><?php dynamic_sidebar( 'right-top' ); ?></div>
	</div>

And my functions.php I used this code:

<?php
/**
 * Generate child theme functions and definitions
 *
 * @package Generate
 */
 
 add_action( 'widgets_init', 'generate_widgets_init' );
	function generate_widgets_init() {
		register_sidebar( array(
			'name'          => __( 'Left Top', 'generate' ),
			'id'            => 'left-top',
			'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
			'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
		) );
	function generate_widgets_init() {
		register_sidebar( array(
			'name'          => __( 'Mid Top', 'generate' ),
			'id'            => 'mid-top',
			'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
			'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
		) );
	function generate_widgets_init() {
		register_sidebar( array(
			'name'          => __( 'Right Top', 'generate' ),
			'id'            => 'right-top',
			'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
			'after_widget'  => '</aside>',
			'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
			'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
		) );

}
?>

The problem is that I'm getting syntax error on my functions.php (line 38), do you know what can I do for fix that?

Hi there,

You're using the same function name as the parent theme, and you're calling it 3 times.

PHP doesn't allow for the same function names to run as it doesn't know which one to read.

Try this:

<?php
/**
 * Generate child theme functions and definitions
 *
 * @package Generate
 */
 
add_action( 'widgets_init', 'generate_custom_widgets_init' );
function generate_custom_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Left Top', 'generate' ),
		'id'            => 'left-top',
		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
	) );

	register_sidebar( array(
		'name'          => __( 'Mid Top', 'generate' ),
		'id'            => 'mid-top',
		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
	) );

	register_sidebar( array(
		'name'          => __( 'Right Top', 'generate' ),
		'id'            => 'right-top',
		'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => apply_filters( 'generate_start_widget_title', '<h4 class="widget-title">' ),
		'after_title'   => apply_filters( 'generate_end_widget_title', '</h4>' ),
	) );

}

Sorry about that - try the code now :)

Yes, that is it! Thank you so much for your support!
Your theme is just awesome!

You just changed the function name?

Yea - generate_widget_init is called in the core theme, and you can't call the same function twice :)

This archived topic is closed to new replies.