Title: Widgets and Custom Fields function just drops
Last modified: August 19, 2016

---

# Widgets and Custom Fields function just drops

 *  [philjohns24](https://wordpress.org/support/users/philjohns24/)
 * (@philjohns24)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/)
 * Hi All,
 * Having a bit of an issue. Im sure its something Im doing in my theme as it seems
   to work for themes that arent created by me!
 * When I add a widget, normally it then shows the options, but it just appears 
   blank until I save it, then options appear.
 * Also, when I add a new custom field to a post, if i click the “Add Custom Field”
   button to save it, nothing happens. If I then click the “Update” post button 
   the custom field appears twice.
 * Any chance someone can spread some light on this?
 * Phil

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [isimpledesign](https://wordpress.org/support/users/isimpledesign/)
 * (@isimpledesign)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920659)
 * check for javascript error using firebug or google chrome. See if it shows some.
 *  Thread Starter [philjohns24](https://wordpress.org/support/users/philjohns24/)
 * (@philjohns24)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920668)
 * Thanks, what page should I check? The pages where the issue is? i.e. the page
   where I write my post and edit the widgets?
 *  Thread Starter [philjohns24](https://wordpress.org/support/users/philjohns24/)
 * (@philjohns24)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920671)
 * Pretty sure its to do with my code in functions.php
 * If I remove some of it, it works, if I put it back and remove the other stuff,
   it works. But not all of it :S
 *     ```
       <?php
       $themename = "PS Rooms";
       $shortname = "wpc";
       $options = array (
   
       array(    "name" => "Welcome Message",
               "type" => "title"),
   
       array(    "type" => "open"),
   
       array(    "name" => "Title",
               "desc" => "Enter a title to display for the introduction title.",
               "id" => $shortname."_welcome_title",
               "std" => "",
               "type" => "text"),
   
       array(    "name" => "Introduction Text",
               "desc" => "Text to display as introduction text.",
               "id" => $shortname."_introduction_text",
               "type" => "textarea"),
   
       array(  "name" => "Disable Welcome Message?",
               "desc" => "Check this box if you would like to DISABLE the welcome message.",
               "id" => $shortname."_welcome_disable",
               "type" => "checkbox",
               "std" => "false"),
   
       array(    "type" => "close")
   
       );
   
       function mytheme_add_admin() {
   
           global $themename, $shortname, $options;
   
           if ( $_GET['page'] == basename(__FILE__) ) {
   
               if ( 'save' == $_REQUEST['action'] ) {
   
                       foreach ($options as $value) {
                           update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
   
                       foreach ($options as $value) {
                           if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
   
                       header("Location: themes.php?page=functions.php&saved=true");
                       die;
   
               } else if( 'reset' == $_REQUEST['action'] ) {
   
                   foreach ($options as $value) {
                       delete_option( $value['id'] ); }
   
                   header("Location: themes.php?page=functions.php&reset=true");
                   die;
   
               }
           }
   
           add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
   
       }
   
       function mytheme_admin() {
   
           global $themename, $shortname, $options;
   
           if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
           if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
   
       ?>
       <div class="wrap">
       <h2><?php echo $themename; ?> settings</h2>
   
       <form method="post">
   
       <?php foreach ($options as $value) {
   
       switch ( $value['type'] ) {
   
       case "open":
       ?>
       <table width="100%" border="0" style="background-color:#efefef; padding:10px;">
   
       <?php break;
   
       case "close":
       ?>
   
       </table><br />
   
       <?php break;
   
       case "title":
       ?>
       <table width="100%" border="0" style="background-color:#dfdfdf; padding:5px 10px;"><tr>
           <td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
       </tr>
   
       <?php break;
   
       case 'text':
       ?>
   
       <tr>
           <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
           <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /></td>
       </tr>
   
       <tr>
           <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
   
       <?php
       break;
   
       case 'textarea':
       ?>
   
       <tr>
           <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
           <td width="80%"><textarea name="<?php echo $value['id']; ?>" style="width:400px; height:200px;" type="<?php echo $value['type']; ?>" cols="" rows=""><?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?></textarea></td>
   
       </tr>
   
       <tr>
           <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
   
       <?php
       break;
   
       case 'select':
       ?>
       <tr>
           <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
           <td width="80%"><select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"><?php foreach ($value['options'] as $option) { ?><option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option><?php } ?></select></td>
       </tr>
   
       <tr>
           <td><small><?php echo $value['desc']; ?></small></td>
       </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
   
       <?php
       break;
   
       case "checkbox":
       ?>
           <tr>
           <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
               <td width="80%"><? if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?>
                       <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> />
                       </td>
           </tr>
   
           <tr>
               <td><small><?php echo $value['desc']; ?></small></td>
          </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px dotted #000000;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
   
       <?php         break;
   
       }
       }
       ?>
   
       <p class="submit">
       <input name="save" type="submit" value="Save changes" />
       <input type="hidden" name="action" value="save" />
       </p>
       </form>
       <form method="post">
       <p class="submit">
       <input name="reset" type="submit" value="Reset" />
       <input type="hidden" name="action" value="reset" />
       </p>
       </form>
   
       <?php
       }
   
       add_action('admin_menu', 'mytheme_add_admin'); ?>
   
       <?php
       add_action('init', 'register_custom_menu');
   
       function register_custom_menu() {
       register_nav_menu('main_menu', __('Main Menu'));
       }
       ?>
   
       <?php
       if ( function_exists('register_sidebar') )
           register_sidebar();
   
       function unregister_default_wp_widgets() {
         unregister_widget('WP_Widget_Calendar');
         unregister_widget('WP_Widget_Search');
         unregister_widget('WP_Widget_Recent_Comments');
         unregister_widget('WP_Widget_Pages');
         unregister_widget('WP_Widget_Archives');
         unregister_widget('WP_Widget_Links');
         unregister_widget('WP_Widget_RSS');
         unregister_widget('WP_Widget_Meta');
         unregister_widget('WP_Widget_Recent_Posts');
         unregister_widget('WP_Widget_Tag_Cloud');
         unregister_widget('WP_Widget_Categories');
   
       }
       add_action('widgets_init', 'unregister_default_wp_widgets', 1);
   
       ?>
   
       <?php
       add_theme_support( 'post-thumbnails', array( 'post' ) );
       set_post_thumbnail_size( 150, 150, true );
       add_image_size( 'featured-post-image', 300, 9999 );
       add_image_size( 'archive-post-image', 230, 180 );
       ?>
       ```
   
 *  [isimpledesign](https://wordpress.org/support/users/isimpledesign/)
 * (@isimpledesign)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920675)
 * hi
 * i had a similar problem that was make the media manager lightbox not work for
   me it was adding jquery like below in my functions.php
 * <?php
    function my_init_method() { if (!is_admin()) { wp_deregister_script( ‘
   jquery’ ); wp_register_script( ‘jquery’, ‘[http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&#8217](http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js&#8217););
   wp_enqueue_script( ‘jquery’ ); } }
 * add_action(‘init’, ‘my_init_method’);
    ?>
 *  Thread Starter [philjohns24](https://wordpress.org/support/users/philjohns24/)
 * (@philjohns24)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920736)
 * I;ve fixed mine now – rewrote my functions.php putting all of my generic wordpress
   calls for thumbnails, menus and sidebars in one php declaration.
 * Is yours fixed now or do you need a hand isimpledesign? Recon I might have a 
   solution if I can see all of your functions.php code?
 *  [isimpledesign](https://wordpress.org/support/users/isimpledesign/)
 * (@isimpledesign)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920737)
 * glad you have sussed it managed to suss mine aswell just included the jquery 
   call in the head instead off trying to call it through the functions.php.
 * Cheers tho 😉

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Widgets and Custom Fields function just drops’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [isimpledesign](https://wordpress.org/support/users/isimpledesign/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/widgets-and-custom-fields-function-just-drops/#post-1920737)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
