webdev.ramyash@gmail.com

Web Development: Create custom widget area in wordpress.


Create custom widget in wordpress.

Create custom widget area in wordpress.

If you are familiar with Wordpress, then you can add easily widget area into the dashboard.

1. Go with an activated WordPress theme, open functions.php and add below code.

<?php

function custom_widgets() {

register_sidebar( array(
'name'          => 'News Sidebar',
'id'            => 'news_sidebar',
'before_widget' => '<div>',
'after_widget'  => '</div>',
'before_title'  => '<h2>',
'after_title'   => '</h2>',
) );

}
add_action( 'init', 'custom_widgets' );
?>

Now ready, go to dashboard widget area drag text or any widget.

2. Call widget where you want to show.

<?php dynamic_sidebar('news_sidebar'); ?>

No comments:

Post a Comment