Radio buttons in widget not saving

Got it, it turns out… The label for each radio button must be the field id / variable, in my example is ‘radio_buttons’ The IF statement for each radio button must refer to this same ID – $radio_buttons === ‘radio_option_1’ & $radio_buttons === ‘radio_option_2’ My new code which works is… <p> <label for=”<?php echo $this->get_field_id(‘text_area’); … Read more

How to add new sidebar widget area to child theme?

Well, this is what worked for me. In my functions.php file I put the following code: function header_widgets_init() { register_sidebar( array( ‘name’ => ‘Header Sidebar’, ‘id’ => ‘header_sidebar’, ‘before_widget’ => ‘<aside class=”widget %2$s”>’, ‘after_widget’ => ‘</aside>’, ‘before_title’ => ‘<h2 class=”widget-title”>’, ‘after_title’ => ‘</h2>’, ) ); } add_action( ‘widgets_init’, ‘header_widgets_init’ ); …and in my header.php file … Read more

Check if widget is active

According to the Codex, you may add some additional parameters to is_active_widget() to make it work. So try this one: if ( is_active_widget(false, false, ‘Search_Widget_Page’, true) ) { // check if search widget is used // Do not display this widget } else { // Display this widget }

Recent Posts widget without Title

This code will set the title to an empty string if it is set to Recent Posts (Which as you noted, is what the Recent Posts widget will set the title to if it is empty): add_filter( ‘widget_title’, ‘wpse_widget_title’, 10, 3 ); function wpse_widget_title( $title, $instance, $id_base ) { if ( ‘recent-posts’ === $id_base && … Read more

How to change text widget title h2 to h1

The before-title and after-title arguments passed to register_sidebar() need to use underscores: register_sidebar(array( “name” => “Home Consulatation”, “id” => “home_consult”, “before_widget” => “”, “after_widget” => “”, “before_title” => “”, “after_title” => “” )); If you use that the titles won’t have any tags. You need to provide them to the before_title and after_title arguments, like … Read more

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