How to group 2 radio buttons in a widget?

The question does not call for WordPress, but it was long to include it in a comment, so here we go. If you want to group your radio buttons, you should specify a name for them. To assign a value, you should change the value property, unlike other form elements. So, let’s have a simple … Read more

Missing argument 2 for a custom function widgets_init

widgets_init isn’t a function, it’s an action hook. The callback you specify for that hook is generate_sidebars which requires two parameters, but the widgets_init hook doesn’t pass any parameters to its callbacks. I think what you’re trying to do is this: add_action( ‘widgets_init’, ‘call_sidebar_function’ ); Which will call the call_sidebar_function() function which will then call … Read more

How to hack recent comments default widget?

Sounds like you just need to make another widget of your own in a plugin. So copy the complete code from the default widgets file, and change the class name, then just edit the code you’d like to edit. class YOUR NEW WIDGET NAME extends WP_Widget { // … foreach ( (array) $comments as $comment) … Read more

Retrieving list of a custom post type in a widget without using WP_Query?

Use wp_reset_postdata() function after while loop to reset custom wp_query as shown in following code so that it will not break other wordpress loop. <?php // Create and run custom loop $custom_posts = new WP_Query(); $custom_posts->query(‘post_type=jobs&posts_per_page=8’); while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/98851/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endwhile; ?> <?php wp_reset_postdata(); ?> For more … Read more

Can I remove a widget area without editing code?

No, is not possible, not in 99% of cases. Widget areas are added with a register_sidebar call in a php file. Until WordPress read that line, the widget area is registered. So, the the easiest and always available way to prevent a widget area is registered is remove (or at least comment out) that line. … Read more

Remove/Unregister or hide a widget added by a plugin

Thanks Stephen for helping me wrap my head around this today. Even though it’s something so small, I absolutely hate when develpers bloat plugins with crap you don’t want. I was very frustrated after WPengine, telling me it can’t be removed and that if I really want to remove it than I need to find … Read more

Too few arguments to function WP_Widget::__construct(),

You’re using an extremely outdated method of creating a widget. You should be using the __construct() function, not a named function, as the constructor, as documented. namespace App; class My_Widget extends \WP_Widget { function __construct() { $widget_ops = [ ‘name’ => ‘My widget’, ‘description’ => ‘My description’ ]; parent::__construct( ‘My_Widget’, ‘My widget’, $widget_ops ); } … Read more

Dynamic Sidebars On Multiple Subpages

More easy & elegant (higher maintainability): <?php // Your sidebar should have the wp_meta action hook wp_meta(); // in ex. your functions.php function my_sidebar_content() { // “About” Page if ( is_page(‘about’) ) { // If some widget is added via Admin > Design > Widgets if ( is_active_sidebar( ‘widgets-sidebar-default’ ) ) { // Display Widgets … Read more