user9294038
user9294038

Reputation: 141

I am trying to display a widget area on my home page

I am trying to display a widget area on my homepage. My result is " Your theme has 1 widget area, but this particular page doesn’t display it.". This is my current attempt and i dont see why this is not working.

This is in the functions.php file

    register_sidebar(array(
     'name'          => __('FirstPage Widget Area', 'jobify'),
     'id'            => 'widget-area-first-page',
     'description'   => __('Choose what should display on the custom static homepage.', 'jobify'),
     'before_widget' => '<section id="%1$s" class="widget widget--home %2$s">',
     'after_widget'  => '</section>',
     'before_title'  => '<h3 class="widget-title widget-title--home">',
     'after_title'   => '</h3>',
 ));

This is in the template file for the homepage, home.php

<?php /* Template Name: Home */

declare(strict_types=1);

get_header();

dynamic_sidebar('widget-area-first-page');

    get_footer();

This is my entire functions.php file

<?php

declare(strict_types=1);

// Register plugin helpers.
require template_path('includes/plugins/plate.php');

// Register post types
require template_path('post-types/index.php');

// Register custom fields
require template_path('custom-fields/index.php');

// Set theme defaults.
add_action('after_setup_theme', function () {
    // Show the admin bar.
    show_admin_bar(false);

    // Add post thumbnails support.
    add_theme_support('post-thumbnails');

    // Add title tag theme support.
    add_theme_support('title-tag');

    // Add HTML5 support.
    add_theme_support('html5', [
        'caption',
        'comment-form',
        'comment-list',
        'gallery',
        'search-form',
        'widgets',
    ]);

    // Add primary WordPress menu.
    register_nav_menu('primary-menu', __('Primary Menu', 'wordplate'));
});

// Enqueue and register scripts the right way.
add_action('wp_enqueue_scripts', function () {
    wp_deregister_script('jquery');

    wp_enqueue_style('wordplate', mix('styles/app.css'));

    wp_register_script('wordplate', mix('scripts/app.js'), '', '', true);
    wp_enqueue_script('wordplate');
});





// Remove JPEG compression.
add_filter('jpeg_quality', function () {
    return 100;
}, 10, 2);

// Set custom excerpt more.
add_filter('excerpt_more', function () {
    return '...';
});

// Set custom excerpt length.
add_filter('excerpt_length', function () {
    return 101;
});

// Functions for translating theme
load_theme_textdomain('Iplay', '/languages');

$locale = get_locale();
$locale_file = "/languages/$locale.php";
if (is_readable($locale_file)) {
    require_once($locale_file);
}

// function includes()
// {
//     $this->files = array(
//             'widgets.php',
//         );
//
//     foreach ($this->files as $file) {
//         require_once(get_template_directory() . '/widgets/' . $file);
//     }
// }


/**
 * Register our sidebars and widgetized areas.
 *
 */

 register_sidebar(array(
     'name'          => __('FirstPage Widget Area', 'iplay'),
     'id'            => 'widget-area-first-page_new',
     'description'   => __('Choose what should display on the custom static homepage.', 'iplay'),
     'before_widget' => '<section id="%1$s" class="widget %2$s">',
     'after_widget'  => '</section>',
     'before_title'  => '<h3 class="widget-title widget-title--home">',
     'after_title'   => '</h3>',
 ));

Upvotes: 0

Views: 1044

Answers (2)

Prakash Singh
Prakash Singh

Reputation: 651

Add this in funtions.php file.

function jobify_widgets_init() {

register_sidebar( array(
        'name'          => __( 'FirstPage Widget Area', 'jobify' ),
        'id'            => 'widget-area-first-page',
        'description'   => __( 'Choose what should display on the custom static homepage.', 'jobify' ),
        'before_widget' => '<section id="%1$s" class="widget widget--home %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title widget-title--home">',
        'after_title'   => '</h3>',
    ) );    

}

add_action( 'widgets_init', 'jobify_widgets_init' );

Add this in your home.php

<?php if ( is_active_sidebar( 'widget-area-first-page' ) ) : ?>
    <?php dynamic_sidebar( 'widget-area-first-page' ); ?>
<?php endif; ?>

Upvotes: 1

PPL
PPL

Reputation: 6565

Try This code:

register_sidebar(array(
     'name'          => __('FirstPage Widget Area', 'jobify'),
     'id'            => 'widget-area-first-page_new',
     'description'   => __('Choose what should display on the custom static homepage.', 'jobify'),
     'before_widget' => '<section id="%1$s" class="widget %2$s">',
     'after_widget'  => '</section>',
     'before_title'  => '<h3 class="widget-title widget-title--home">',
     'after_title'   => '</h3>',
 ));

Hope this work for you.

Upvotes: 0

Related Questions