Adding a single text input field to a custom Dashboard widget

You need a set of functions to : process datas sanitize options allow datas to be updated output the form I like to proceed this way. I set also a function to grab datas so I can call them the simpliest way : add_action(‘wp_dashboard_setup’, ‘wpse_106458_add_widget’); function wpse_106458_add_widget() { $title = my_function_get_options(); $title = $title[‘title’]; wp_add_dashboard_widget(‘widget_id’, … Read more

Creating a custom wordpress widget and stopping js from running twice(once in active widget once in widget selector)?

Use wp_enqueue_script. You assign a name to your js file when enqueued, and it will stop a file from being enqueued multiple times. Right now your JS is simple enough, but as it gets more complex, it’s better to have it outside in it’s on .js file. add_action( ‘wp_enqueue_scripts’, ‘add_my_js’ ); function add_my_js() { wp_enqueue_script( … Read more

Sidebar widgets – dynamic CSS : problem with widget-title

Not a good solution… but is a solution: using jquery. register_sidebar( array ( ‘name’ => ‘Left Widget Area’, ‘id’ => ‘primary_widget_area’, ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”><div class=”widget-title”></div><div class=”widget-content”>’, ‘after_widget’ => ‘</div></li><!– .widget –>’, ‘before_title’ => ‘<span class=”invisible-title” data-widget=”%1$s” style=”display:none;”>’, ‘after_title’ => ‘</span>’, ) ); and the JS jQuery().ready(function($) { $(‘.invisible-title’).each(function() { var title = … Read more

WordPress dynamic widget by location?

try to make a simpler code: change $side_bar= “‘$city-Right'”; to $side_bar= $city . ‘-Right’; you have extra ‘ in $side_bar, the way you’ve done would give you ‘Madurai-Right’ but you need Madurai-Right, this way dynamic_sidebar($side_bar) would be like writing dynamic_sidebar(“‘Madurai-Right'”) while you only need dynamic_sidebar(“Madurai-Right”) besides, always avoid variable substitution, concatenation is always more secure.

How to display a widget on a page with no theme?

You should read this. It’s completely possible, but you have to go through the right process. First you should register a new “sidebar” and call it whatever you want to call that page you want the widget to display on. Then you need to call that sidebar into the page’s template file, after which you … Read more

Conditional widget_form_callback

You need to get the array of sidebars and their widgets with wp_get_sidebars_widgets(), then check if the current widget is in the ‘footer’ sidebar: $sidebars = wp_get_sidebars_widgets(); if ( in_array( $widget->id, $sidebars[‘footer’] ) ) { /* Display form fields here */ } Update: There is one caveat to this, which you have discovered. The widget … Read more

My widget won’t update its values when save is clicked

In $control_ops = array( ‘width’ => 300, ‘height’ => 350, ‘id_base’ => ‘example-widget’ ); id_base should be without space and in your rollover image, your name is wrong, you have the name set to echo $this->get_field_name( ‘image’ ); when it should be echo $this->get_field_name( ‘rollover_image’ ); add_action ( ‘widgets_init’ , ‘my_widget’ ) ; function my_widget … Read more