Tag Info

New answers tagged

4

Looking at the source code that WordPress uses to register widgets here, there's a $number parameter defined, in line 242, as: The unique order number of this widget instance compared to other instances of the same class. The function _set($number) stores this ID number attached to the base identifier string of the widget. Then, the function ...


2

In Twenty Fourteen, when you first activate the theme without any changes made to the theme, the widgets that appear there on the sidebar are from the dashboard. You can remove them from Appearance > Widgets and you'll see Search, Recent Posts, Recent Comments etc. in the meta-box "Primary Sidebar". If you want to see the code for the primary sidebar, it's ...


1

I used Stephen Harris suggested method. $dummy = new My_Widget_Class(); $settings = $dummy->get_settings(); $settings = reset($settings); reset() gives the first key value from array, if you don't know what is the ID of your widget. Note: It does not help if there multiple copies of widget is active. Because it returns the settings of the first copy ...


0

Got it. So here's how you insert a hover state halfway the processing of a page without violating the w3c rules. This is the code you don't want your widget to produce: <div class="mywidget"> <style>.mywidget a {color:red}, . mywidget a:hover {color:blue;}</style> <a>Link</a> </div> The following validates and is fairly ...


0

Looking at your site, it seems that the broken image on the top left side is your logo. I suspect there might be a logo upload for the theme but we won't be able to direct you to where that logo upload form is because it can vary depending on the theme. You'll want to check for the theme options area often located under the Appearance menu in the admin ...


0

You can use set_query_var('myvarname', $myvarvalue); before get_template_part(). Then in your loop template you can access the var using $myvarname. You can also skip all that and use locate template instead.


1

The form reloads itself each time you save returning to the initial state where all are shown. What you can do is this: // Getting the value of the selected field var my_select_value = $('#widgets-right select.my-select').val(); // If there's no value selected, hide everything. if(my_select_value == 0){ $('.widget-test .row').hide(); } // Otherwise, ...


1

Use the use keyword: $title = $instance['title']; add_action( 'wp_footer', function() use ( $title ) { echo $title; });


0

i was using get_sidebar() instead of dynamic_sidebar('name')....


0

From the Wordpress Codex: is_active_sidebar() This Conditional Tag checks if a given sidebar is active (in use). This is a boolean function, meaning it returns either TRUE or FALSE. Any sidebar that contains widgets will return TRUE, whereas any sidebar that does not contain any widgets will return FALSE. So you should be able to do something ...


1

Use the array_filter() function, which will remove every array element that has false as the value. Then you can count the array length. So your example would look like this: $sidebars = array( is_active_sidebar( 'footer-4' ), is_active_sidebar( 'footer-3' ), is_active_sidebar( 'footer-2' ), is_active_sidebar( 'footer-1' ), ...


2

You could add this function to your functions.php file. add_filter( 'sidebars_widgets', 'disable_all_widgets' ); function disable_all_widgets( $sidebars_widgets ) { $sidebars_widgets = array( false ); return $sidebars_widgets; } You could also use the Wordpress conditional tags to disable widgets only on certain pages. For example; this would only ...


0

Below is the code you need. Your issue could be that you're not first setting up the variable $display_options to contain your options, or that you not asking if the option is set. add_action('widgets_init', 'arphabet_widgets_init'); function arphabet_widgets_init() { $options = get_option('muffin_options'); ...


0

I am not exactly sure what you're question is but I think you are looking for something like this, mostly cribbed from the Codex: if ( is_active_sidebar( 'sidebar-1' ) ) { ?> <ul id="primary"><?php dynamic_sidebar( 'sidebar-1' ); ?> </ul><?php } If the sidebar is not in use, no markup will display. You could add ...


1

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


0

The Missing Arguments error disappeared after making a small change to the parameters in the function: function remove_widget_title($title, $instance) to: function remove_widget_title($title, $instance = [])


1

You don’t pass more than argument to that filter, so any callback expecting more than one will not get it. The core calls this filter always like this: $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base ); But you are passing just $instance['title']. Add the missing ...


0

You need an update method which saves your widget settings: function update( $new_instance, $instance ) { for ( $i=0; $i < 3; $i++ ) $instance[ "link_target_$i" ] = $new_instance[ "link_target_$i" ]; return $instance; }


2

The most likely problem is that the theme is outdated and no longer compatible with some core WP functions, the theme was released in 2012 so it's pretty old.


2

I think the easiest way is adding the form via the Shortcode API. The code would look like this: function myform_handler( $atts ){ if (isset(@$_REQUEST['submit'])) { //Do something } else { $return = '<form action="" method="post"> <input type="text" name="myfield"> <input ...


2

Any widgets written to operate as the Core "Recent Posts" widget does can be forced to skip the title by a filter on widget_title: function widget_title_hack_191120($title, $instance) { if (empty($instance['title'])) { $title = ''; } return $title; } add_filter('widget_title','widget_title_hack_191120', 10, 2); I don't know if there is a generic ...


0

This is memory and I can't test right now, but I believe the title is always set. Use !empty( $settings['title'] ) instead and I think you will get the results you expect.



Top 50 recent answers are included