Hot answers tagged

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(){ ...


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 { ...


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

Since it sounds like you're trying to do this without code I would do it this way: Create an 'Advertisement' post type which supports categories. Then use a 'Related Posts' widget that allows you to select custom post types as well as related categories. Possibly one of these And use the widget settings to call the appropriate Ad UPDATE: Not sure how clear ...


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, $...


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>',


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']; ...


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.


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.


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&...



Only top voted, non community-wiki answers of a minimum length are eligible