Skip to main content
fixed code rendering. see how to display code by using markdown here http://daringfireball.net/
Source Link

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' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ) ); } }

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


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 :)

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' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ) ); } }

// 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 :)

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 :)

Source Link
morktron
  • 253
  • 1
  • 2
  • 11

How to conditionally add a widget via a hook in functions.php

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' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ) ); } }

// 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 :)