- This topic has 3 replies, 4 voices, and was last updated 3 years, 10 months ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I am adding the following code to functions.php
function wpblog_widget()
{
register_sidebar(array(
'name' => __('Primary Sidebar', 'wpb'),
'id' => 'primary_sidebar', // unique-sidebar-id
'description' => '',
'class' => '',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
add_action('widgets_init', 'wpblog_widget');
This is to register a widget and to make the widget area visible I am dding this code in sidebar.php
<?php if ( is_active_sidebar( 'Primary Sidebar' ) ) : ?>
<?php dynamic_sidebar( 'Primary Sidebar' ); ?>
<?php endif; ?>
I don’t know why it is not working? I have seen the code here https://www.wpblog.com/how-to-add-custom-widget-area-to-wordpress-themes/
Is your widget position showing in the backend? And if so, what have you tried to include in that widget position?
I think you should be extending the WP_Widget class.
This tutorial looks pretty good:
https://kinsta.com/blog/create-wordpress-widget/
I am trying to say yo just add some step , i hope you can add custom widgets
Create your widget’s class by extending the standard WP_Widget class and some of its functions.
Register your widget so that it’s made available in the Widgets screen.
Make sure that your theme has at least one widget area in which to add the widgets.