0

I have a front-page.php defining the homepage of my theme (a Genesis child theme).

In it, I have some custom widget areas, like so:

genesis_register_sidebar( array(
    'id'    => 'cta',
    'name'    => __( 'How do I Connect?', 'site' ),
    'description'    => __( 'This is the cta widget for the home page.', 'site' ),
) );

add_action( 'genesis_after_header', 'cta_widget' );

function cta_widget() {
   genesis_widget_area( 'cta', array(
       'before' => '<div class="cta widget-area"><div class="wrap"><h2>How do I <strong>Connect?</strong></h2>',
       'after' => '</div></div>'
   ) );
}

I originally had it in the functions.php and it worked fine.. I added some widgets to it, etc with no problems. But now I moved it to front-page.php as I saw mentioned as a way to restrict it to the home page, and now it is listed under inactive widgets, although I can still edit them it is confusing for the user, plus I cannot add any more in this way. Is this expected behaviour?

  • 1
    Please note that we cannot answer questions for products without source code publicly available. I would guess it's not working in template file because it shouldn't be in template file, but there isn't much value in guessing. – Rarst Jul 18 '13 at 23:01
  • Ah I didn't presume it was a Genesis specific issue.. – Damon Jul 19 '13 at 13:05
  • It might not be, but that's the issue - it is impossible to even say confidently if it is without seeing what code does. – Rarst Jul 19 '13 at 13:12
  • Well your guess was correct. I moved just the register_sidebar definitions to functions.php and everything is working properly. – Damon Jul 19 '13 at 13:22
2

Is this expected behaviour?

Yes, it is expected behavior. The genesis_register_sidebar() function is just a call to register_sidebar() with a few predefined defaults for $args and a filter named 'genesis_register_sidebar_defaults':

function genesis_register_sidebar( $args ) {

    $defaults = (array) apply_filters(
        'genesis_register_sidebar_defaults',
        array(
            'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-wrap">',
            'after_widget'  => "</div></div>\n",
            'before_title'  => '<h4 class="widgettitle">',
            'after_title'   => "</h4>\n",
        )
    );

    $args = wp_parse_args( $args, $defaults );

    return register_sidebar( $args );
}

Since the front-page.php child theme file is not (normally) run during an admin page load, the widget is not registered and will not appear in the Active Widgets area. As you correctly surmised in the comments, placing the call to genesis_register_sidebar() in the functions.php child theme file registers the widget when admin pages are loaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.