New answers tagged

0

dashboard widgets api to create the widget "wrapper" wp count posts to count number of items in a post type wp count terms to count items in a taxonomy (will need to use get_terms to get every term then use wp_count_terms in the loop) That should get you close to what you want :)


0

Going through its normal proceedings Wordpress will already have evaluated wp_head by the time it gets to the widgets. The dynamic_sidebar_params filter will only be called then as well, so it will also be of little help to get your css in the head. Here's something I wrote about this issue earlier. To include information from widget settings in the head, ...


1

I did this for a client and it looked like this: The PHP code: <dl class="tree-accordion"> <?php $currentyear = date("Y"); $years = range($currentyear, 1950); foreach($years as $year) { ?> <dt><a href=""><i class="fa fa-fw fa-plus-square-o" aria-hidden="true"></i> <?php echo $year; ?></a&...


1

You can you wp_parse_args to merge $instance with a default array. So, you would start you form function not with extract($instance) but with $defaults = array( 'title' => 'Your title', 'text' => '...', 'image_url' => '...' 'textarea' => '...' ); $instance = wp_parse_args((array) $instance, $...


4

You do not need to create a complete new widget to do what you need to do. As I read your question, you are just interested in changing how the categories are displayed on the front end. There are two functions that displays the categories on the front end wp_list_categories() which displays the categories in a list wp_dropdown_categories() which displays ...


4

You can override the default WordPress widgets by extending them. The code for the default Categories widget can be found on the following link: https://developer.wordpress.org/reference/classes/wp_widget_categories/widget/ and below is an example code how you can override the output of the widget. Class My_Categories_Widget extends WP_Widget_Categories { ...


7

To expand on Mark's answer, there's not much (generally) available in the way of filters in the default WordPress widgets (except for perhaps widget_text). But adding your own custom widget is easy - put this in your functions.php: require_once("my_widget.php"); add_action("widgets_init", "my_custom_widgets_init"); function my_custom_widgets_init(){ ...


1

Check this out, it may guide you in the direction you need: First: register_sidebar( array( 'name' => 'Social Media button', 'id' => 'smb', 'before_widget' => '<li>', 'after_widget' => '</li>', ) ); Second code: public function widget( $args, $instance ) { $output = $args['before_widget']; ...


0

Looking at the function source on https://developer.wordpress.org/reference/functions/wp_list_authors/ you can see that the post type of post is hard coded into the sql query that returns the authors and post counts. You could clone the function and add other post types as an argument, but I don't see a more elegant solution sadly.


0

This works for me tested on WordPress 4.5.2 function nand_filter_widget_titles($title) { if ( $title != '') { $title = '<span class="icon-someicon">' . $title . '</span>'; } return $title; } add_filter( 'widget_title', 'nand_filter_widget_titles' );


1

In the register_sidebar() call in functions.php. Look for before_widget and after_widget and modify as appropriate. The code below is the default usage. 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>',


0

What you want is probably better to do with css by applying a display:inline; style to the specific widget. something like #id.textwidget { display:inline; } Where "id" is the id attribute of the widget. If you don't have one you should change your sidebar registration code to create one. I don't think it is very likely that you will want such a ...


1

More than likely this is an issue with the register_sidebar() call in functions.php. Look for before_widget and after_widget. The code below is the default usage. 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', Note: This will alter all of the widgets within the sidebar, not just the TextWidget.


0

Your widget is okay but problem is customizer do not show sidebar option if there is no sidebar is called on current viewing page. You did register the two siderbars but did not call them any where in the template of page your are seeing in customizer. Use dynamic_sidebar function and call your sidebar somewhere in the template. Example:- dynamic_sidebar(...


0

You should make the check inside the widget class, unless you don't have a choice. The example in the codex is pretty much what you're looking for: class cbs_map_widget extends WP_Widget{ function cbs_map_widget(){ $this->WP_Widget('cbsmaps', __('Widget Name'), array('classname' => 'cbsmaps', 'description' => __('whatever'))); ... ...


0

You might be forgotten to add wp_footer(); function before the closing body tag in your footer.php. That causes the javascript cannot finish its instruction in the customizer.


2

Once the widgets are being evaluated, the head of your site is completed, so you cannot use wp_head anymore. Adding <style> tags is an option, but will indeed generate a warning from the validator. Using the customizer is possibly confusing, because it is supposed to be about theme looks in general, not about specific widgets. You can however, make ...


1

You need to pass more query arguments. In this case you need: $args = array( 'post_type' => 'post', 'posts_per_page' => $instance['limit'], 'category__in' => $id ); Where $id is the category id, not the post id.


0

I solved the issue. Here's a link where I explain how I solved it and how the final code looked like: https://wordpress.org/support/topic/customize-dashboard-widgets-for-individual-users-1?replies=11



Top 50 recent answers are included