0

I'm trying to add some widget areas to the homepage only using functions.php - so that the client won't be able to accidentally destroy shortcode when editing the page.

I've registered the widget area and can see it in admin, but nothing shows up on the frontend, except my test text which is outside of the widget area.

This is what I have so far:

<?php

add_action( 'widgets_init', 'register_widget_area' );
function register_widget_area() {
    // Add fox_home_news_widget to admin
    if( function_exists( 'register_sidebar' ) ) {
        register_sidebar( array(
            'name' => 'Fox News',
            'id' => 'fox_home_news_widget',
    'description' => "Latest news widget area for homepage",
            'before_widget' => '<aside class="fox-news">',
            'after_widget' => '<div class="fix"></div></aside>',
            'before_title' => '<h1 class="title">',
            'after_title' => '</h1>',
        ));
    }
}

// add widget areas to homepage 
add_action( 'woo_post_after', 'fox_home_news_widget' );
function fox_home_news_widget () { 
if( is_page( 15 ) ): ?>

        <div class="twocol-one">

            <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('fox_home_news_widget') ) ; ?>

                <p>this is a test</p>
        </div>

    <?php endif;
}

?>

Any help would be much appreciated, thanks :)

  • Sorry the code rendering is not working well here, probably because I'm going in and out of php. – morktron Jul 19 '13 at 7:14
1

One thing, that is off topic, but catches my eye at first glance, is that the php-code and the div-tag in the template are nested in a wrong way. They should be nested like this:

    <div class="twocol-one">
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('fox_home_news_widget') ) ; ?>

            <p>this is a test</p>

        <?php endif;?>
    </div>

And you are missing the closing ?> on the endif-statement.

  • Thanks Creech, yes it does look like it should be as you say. I tried it though but it shows a syntax error. I think the endif is for closing the if statement above that says: if( is_page( 15 ) ): ?> – morktron Jul 19 '13 at 10:44

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.