How to show widget in frontend?
-
**I’m sorry about my english.
I’m newbie in wordpress. I try to create a small widget for embed video from youtube or others video hosting. Everything is going well in backend (WordPress adminsitrator).
This is the print screen >> https://i.imgur.com/jfedV4R.gif
When i publish the widget in my sidebar, the widget does not appear anything. But work fine in my backend.
This is my widget code:
<?php /** * Today Video Widget Class * */ class Today_video extends WP_Widget { /** * Widget setup. */ function Today_video () { /* Widget settings. */ $widget_ops = array( 'classname' => 'tm_widget_today_video', 'description' => __('Display today video on your site', 'today_video') ); /* Widget control settings. */ $control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'today_video' ); /* Create the widget. */ $this->WP_Widget( 'today_video' , __( 'Today Video' , 'today_video' ), $widget_ops, $control_ops ); } /** * The frontend function */ function widget( $args, $instance ) { extract( $args ); /* Our variables from the widget settings. */ if(isset($instance)) { if( isset( $instance[ 'title' ] ) ) { $title = apply_filters( 'widget_title', $instance[ 'title' ] ); } if( isset( $instance[ 'template' ] ) ) { $template = htmlspecialchars_decode( $instance[ 'template' ] ); } } } /** * Backend widget settings */ function update( $new_instance, $old_instance ) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags( $new_instance['title'] ); // htmlspecialchars to save html markup in database, at frontend we use htmlspecialchars_decode $instance['template'] = htmlspecialchars($new_instance['template']); return $instance; } /** * Displays the widget settings controls on the widget panel. * * Backend widget options form */ function form( $instance ) { $defaults = array( 'title' => __( 'Today Video', 'today_video'), 'template' => __('<iframe width="200" height="150" src="https://www.youtube.com/embed/tv49TbW5rEg" frameborder="0" allowfullscreen></iframe>', 'today_video'), ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label> <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:96%;float:right;" /> </p> <p> <textarea id="<?php echo $this->get_field_id( 'template' ); ?>" name="<?php echo $this->get_field_name( 'template' ); ?>" style="width:100%;height:100px;"><?php echo $instance['template']; ?></textarea> </p> <?php } } //Add function to widgets_init that'll load today_video add_action( 'widgets_init', create_function( '', 'register_widget( "Today_video" );' ) ); ?>
Can someone help me, Please!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to show widget in frontend?’ is closed to new replies.