I need to disable drag&drop functionality for dashboard widgets.
This should be realized with jquery, just as it is for the dashboard_browser_nag. I’m no jquery expert – so can anybody tell me how to find and modify my widgets with jquery?
So far, I know that I have to do some .sortable(“cancel”), but how exactly?
Thanks!
This will remove the draggable functionality from each widget:
You have find a good way to inject this into your code, either through
wp_enqueue_script()
or echo it inline on the Widget page.To target a specific Widget you would have to do something along these lines:
Or select your way around to find the widget by
id
:If you browse around the source you’ll soon find out how these are internally formed by WordPress. The rest is up to jQuery, selectors, maybe regular expressions (though I don’t recommend them in this case).
Not tested, but this would atleast get you started. Add this to functions.php or make your own plugin for it.
Interesting approach. Isn’t working like that however. My best so far is to prevent adding any footer scripts:
Clearly not a good solution. But the suggested
wp_dequeue_script
function to remove a single script is not working – maybe ‘wp_dashboard_setup’ is the wrong hook? I also tried to hook into ‘wp_default_scripts’ and to modify$wp_scripts
itself, but without any success…@Ijaas: good point, it would also break admin_widgets and admin_gallery, but isn’t it possible to add the action/filter depending on the
$current_screen
? Should be, as it is a footer script which is added afterset_current_screen()
was called.