Script to remove all inactive widgets?
something like: $widgets = get_option(‘sidebars_widgets’); $widgets[‘wp_inactive_widgets’] = array(); update_option(‘sidebars_widgets’, $widgets);
something like: $widgets = get_option(‘sidebars_widgets’); $widgets[‘wp_inactive_widgets’] = array(); update_option(‘sidebars_widgets’, $widgets);
Here is an interesting approach: THE PLAN AND LOGIC: Custom fields are a build in functionality that will fit our needs perfectly. We can set a new custom field and then use that field to enter and store our custom data. We can then use a widget to display this custom content in the sidebar … Read more
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 elegant. In your widget generate the … Read more
Workaround using jQuery DOM insertion. Note the use of PHP Heredoc sintax to print the script. function wpse_53035_script_enqueuer(){ echo <<<HTML <script type=”text/javascript”> jQuery(document).ready( function($) { $(‘<div style=”width:100%;text-align:center;”><img src=”http://cdn.sstatic.net/wordpress/img/logo.png?v=123″></div>’).insertBefore(‘#welcome-panel’); }); </script> HTML; } add_action(‘admin_head-index.php’, ‘wpse_53035_script_enqueuer’); This inserts the new div at the top before #welcome-panel. If you use the div #dashboard-widgets-wrap it prints in the same … Read more
Simple way would be to set some global variable on first widget run and check for it. Output nothing or informational message if it is already set. Proper way would probably be to work with interface and remove widget from available when you add it to sidebar, but that is way out of my league.
Hook into ‘dynamic_sidebar’ and count how often it is called. You get the current active sidebar with key( $GLOBALS[‘wp_registered_sidebars’] ). add_action( ‘dynamic_sidebar’, ‘wpse_96681_hr’ ); function wpse_96681_hr( $widget ) { static $counter = 0; // right sidebar in Twenty Ten. Adjust to your needs. if ( ‘primary-widget-area’ !== key( $GLOBALS[‘wp_registered_sidebars’] ) ) return; if ( 0 … Read more
This can be solved using custom meta fields in the user profile (only visible to administrators) and then making an individual dashboard widget containing this meta (only visible if certain criteria is met). Adding fields to the user profile page can be done: 1) manually Following Justin Tadlock’s tutorial: Adding and using custom user profile … Read more
Yes you can create a widget and set the content from the back-end. You can also do it by a plugin. But since you asked for a widget, I did write a full widget for you. The code is plenty self explanatory, since I added details for every line. I didn’t copy your code to … Read more
Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( ‘description’ => ‘Display Some Hard Coded PHP content’ ); parent::WP_Widget( ‘my-hc-php-content’, ‘Some PHP’, $opts ); } function widget($args,$instance) { // PHP goes here, like this: echo ‘PHP generated content’; } … Read more
I know this is a super old question, but searching for solutions 8 years later didn’t yield many results aside from this unresolved question (and a few other vague answers). Nothing I found on this site worked for me so if others arrive on this page looking for a way to limit a widget-area to … Read more