Javascript,Nodejs,MongodDB,WordPress,CSS,PHP

LightBlog

Sunday, November 18, 2018

How to create sidebar

WordPress widgets were created to provide a simple and easy-to-use way of giving design and structure control of the WordPress theme to the user. Widgets can be easily dragged and dropped into a specific widget area.
where to write this code? in your functions.php your active themes
Syntax:

<?php 
wp_register_sidebar_widget(
    $id, 
    $name, 
    $output_callback, 
    $options, 
    $params,
    
); 
?> 

Parameters:

$id: widget id required
$name: widget display sidebar name this is required
$output_callback: run when widget is called 
$options:widget options
$params: widget parameters to add to widget

Example: 

<?php

function your_widget_display($args) {
   echo $args['before_widget'];
   echo $args['before_title'] . 'My Unique Widget' .  $args['after_title'];
   echo $args['after_widget'];
   // print some HTML for the widget to display here
   echo "Your Widget Test";
}

wp_register_sidebar_widget(
    'your_widget_1',        // your unique widget id
    'Your Widget',          // widget name
    'your_widget_display',  // callback function
    array(                  // options
        'description' => 'Description of what your widget does'
    )
);

?>
call sidebar anywhere in your template
 <?php dynamic_sidebar("your_widget_id"); ?> 
Source File:
wp_register_sidebar_widget() is located in wp-includes/widgets.php.

No comments:

Post a Comment