When you register a sidebar in WordPress, is it possible to choose in what order it appears in the admin

Sidebars are output in registration order, which is implicitly captured by how they are added to a $wp_registered_sidebars global. This can easily be manipulated, for example following code will move first sidebar to the start: add_action( ‘register_sidebar’, function ( $sidebar ) { global $wp_registered_sidebars; if ( ‘first’ === $sidebar[‘id’] ) { $sidebar = $wp_registered_sidebars[‘first’]; unset( … Read more

Adding a widget to a string of HTML

If you want to add the widget area as part of the output var you need to use the ob functions because it is echoed and not returned. Like this: $output .= ‘<div id=”header-image-widget-area”>’; ob_start(); dynamic_sidebar( ‘header_image_widget’ ); $output .= ob_get_clean(); $output .='</div>’;

WordPress Widget multiple use

You need to implement your Widget using the Widgets API, so that WordPress knows how to make multiple instances of the Widget. Your Widget declaration should take the following format: class My_Widget extends WP_Widget { function My_Widget() { // widget actual processes } function form($instance) { // outputs the options form on admin } function … Read more

wordpress widget textbox in the sidebar

check your sidebar.php and functions.php of the theme, the sidebar define the markup outside the widget; the function register_sidebar() defines the markup before content of the widgets; this markup you must change. See the codex for this function: codex register_sidebar() Edit Specifically, you need to look at the before_widget and after_widget parameters of the register_sidebar() … Read more

Use wp_enqueue_style based on user option in widget

This is sort of sloppy as the style will still be enqueued regardless. In the code to display your widget, change the CSS selectors based on whether or not the user selected own style: <?php $prefix = $instance[‘own_style’] ? ‘ownstyle_’ : ‘pluginstyle_’; //then…. ?> <div id=”<?php echo $prefix; ?>selector”> …</div> etc A user would be … Read more

Widget queries even when there are no sidebars?

Does unregistering them the also disable the database queries? Goes in functions.php: //Unregister all Default Widgets function unregister_default_wp_widgets() { unregister_widget(‘WP_Widget_Pages’); unregister_widget(‘WP_Widget_Calendar’); unregister_widget(‘WP_Widget_Archives’); unregister_widget(‘WP_Widget_Links’); unregister_widget(‘WP_Widget_Meta’); unregister_widget(‘WP_Widget_Search’); unregister_widget(‘WP_Widget_Text’); unregister_widget(‘WP_Widget_Categories’); unregister_widget(‘WP_Widget_Recent_Posts’); unregister_widget(‘WP_Widget_Recent_Comments’); unregister_widget(‘WP_Widget_RSS’); unregister_widget(‘WP_Widget_Tag_Cloud’); } add_action(‘widgets_init’, ‘unregister_default_wp_widgets’, 1);

Elegantly using JavaScript on widget admin forms

One way around this I’ve discovered since posting the above question is to instantiate inline via WP_Widget::form(), with wp_enqueue_script() loading the necessary JavaScript (exactly as mentioned above) — except, and here’s the key part, load the JavaScript in the header instead of the footer (fifth argument of wp_enqueue_script()). Which makes a lot of sense now … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)