Skip to content

Instantly share code, notes, and snippets.

@juyal-ahmed
Last active August 29, 2015 14:07
Show Gist options
  • Save juyal-ahmed/f006eb2362ea08d1f348 to your computer and use it in GitHub Desktop.
Save juyal-ahmed/f006eb2362ea08d1f348 to your computer and use it in GitHub Desktop.
Auto fill input values for WordPress Unique Page Sidebars [Plugins] when creating a dynamic sidebar with default values
/*
---------------------------------------------------------------------------------------
Auto fill input values for WordPress Unique Page Sidebars [Plugins] when creating a dynamic sidebar with default values
---------------------------------------------------------------------------------------
*/
jQuery(document).ready( function($) {
//Finding all inputs from unique page sidebars when creating a sidebar
$("input[id^=ups_sidebars]").each( function( k, v ) {
//Finding current input fields id
id = $( this ).attr( 'id' );
//Check if it has a default value already
if ( $( this ).val() == '' ) {
//Matching if it is the before_title field
before_title = id.match(/\bbefore_title/);
if ( before_title ) {
$( this ).val( '<h3 class="widget-title">' );
}
//Matching if it is the after_title field
after_title = id.match(/\bafter_title/);
if ( after_title ) {
$( this ).val( '</h3>' );
}
//Matching if it is the before_widget field
before_widget = id.match(/\bbefore_widget/);
if ( before_widget ) {
$( this ).val( '<div id="%1$s" class="widget %2$s">' );
}
//Matching if it is the after_widget field
after_widget = id.match(/\bafter_widget/);
if ( after_widget ) {
$( this ).val( '</div>' );
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment