Tagged: x
-
AuthorPosts
-
August 8, 2016 at 6:11 am #1121953
509WebDesignerParticipantI was wanting a way to add the X Social buttons to the sidebar quickly and found this not possible. So I thought I would make one and add it here. Not sure if this will help anyone, or if this could be included in the official release, or if this is even the right place for this.
Add the below code to functions.php in your child theme and you will have a widget called “X Social Widget” that you are free to place like any other, and operates just as the other buttons do. You can also modify them through CSS separately since they are under a widget and given a unique class name.
function register_x_social_widget() { register_widget( 'x_social_widget' ); } add_action( 'widgets_init', 'register_x_social_widget' ); class x_social_widget extends WP_Widget { /** * Holds widget settings defaults, populated in constructor. * * @var array */ protected $defaults; /** * Register widget with WordPress. */ public function __construct() { $widget_ops = array( 'classname' => 'x_social_widget', 'description' => 'Display the X Social Buttons in the sidebar.', ); parent::__construct( 'x_social_widget', 'X Social Widget', $widget_ops ); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ function widget( $args, $instance ) { extract( $args ); /** Merge with defaults */ $instance = wp_parse_args( (array) $instance, $this->defaults ); echo $before_widget; if ( ! empty( $instance['title'] ) ) echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; echo x_social_global(); echo $after_widget; } function form( $instance ) { /** Merge with defaults */ $instance = wp_parse_args( (array) $instance, $this->defaults ); ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'evolution' ); ?>:</label> <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" /> </p> <?php } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ function update( $new_instance, $old_instance ) { $new_instance['title'] = strip_tags( $new_instance['title'] ); return $new_instance; } }August 8, 2016 at 7:38 am #1122014
ChristianModeratorThanks for sharing. 🙂
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1121953 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
