Title: Problem with functions.php
Last modified: August 19, 2016

---

# Problem with functions.php

 *  [erikw46](https://wordpress.org/support/users/erikw46/)
 * (@erikw46)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/problem-with-functionsphp/)
 * I am having been adding some features to my site through the functions.php however
   in the last day or so it has started giving me this error:
 * Warning: Cannot modify header information – headers already sent by (output started
   at /home4/rhythmsn/public_html/wp-content/themes/rhythm2012/functions.php:269)
   in /home4/rhythmsn/public_html/wp-includes/pluggable.php on line 890
 * Any helps would be much appreciated. Here is my functions.php
 *     ```
       <?php
   
       // ------------------------- General -------------------------
   
       // Custom CSS styles on WYSIWYG Editor - Start
   
       	if ( ! function_exists( 'myCustomTinyMCE' ) ) :
       	function myCustomTinyMCE($init) {
       		$init['theme_advanced_disable'] = 'outdent, separator, strikethrough, blockquote, indent, justifyleft, justifycenter, justifyright, justifyfull, bullist, numlist, outdent, indent, fontselect, fontsizeselect, forecolor, backcolor, forecolorpicker, backcolorpicker, formatselect'; // Removes the undesired buttons
       		$init['theme_advanced_buttons2_add_before'] = 'styleselect'; // Adds the buttons at the begining. (theme_advanced_buttons2_add adds them at the end)
       		$init['theme_advanced_styles'] = 'Photo Caption=caption';
       	 return $init;
       	}
       	endif;
       	add_filter('tiny_mce_before_init', 'myCustomTinyMCE' );
       	add_filter( 'mce_css', 'tdav_css' );
   
       	// incluiding the Custom CSS on our theme.
   
       	function mycustomStyles(){
       		wp_enqueue_style( 'myCustomStyles', get_bloginfo('template_url').'/css/tinyMCE.css', '','','all' );
       	}
       	add_action('init', 'mycustomStyles');
   
       // Custom CSS styles on WYSIWYG Editor - End
   
       // ------------------------- Remove Dashboard Widgets -------------------------
   
       // remove dashboard widgets
       function example_remove_dashboard_widgets() {
   
       // load the metaboxes array as a global variable
       global $wp_meta_boxes;
   
       // side widgets
       unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
       unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
   
       //normal widgets
       unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
       unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
       }
   
       // Hoook into the 'wp_dashboard_setup' action to remove the widgets defined above
       add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );
   
       // ------------------------- Remove Menu Items -------------------------
   
       // function to remove the Links menu item
       function remove_menus() {
   
       // setup the global menu variable
       global $menu;
   
       // this is an array of the menu item names we wish to remove
       $restricted = array( __('Links'),__('Tools'),__('Settings'),__('Comments'));
       end ($menu);
   
       while (prev($menu)) {
       $value = explode(' ',$menu[key($menu)][0]);
   
       if(in_array($value[0] != NULL?$value[0]:"" , $restricted)) {
       unset($menu[key($menu)]);
       		}
       	}
       }
   
       // hook into the action that creates the menu
       add_action('admin_menu', 'remove_menus');
   
       // ------------------------- Events -------------------------
   
       // Custom Post Type for Events
   
       add_action( 'init', 'create_Events' );
       function create_Events() {
         $labels = array(
           'name' => _x('Events', 'post type general name'),
           'singular_name' => _x('Events', 'post type singular name'),
           'add_new' => _x('Add New', 'Event'),
           'add_new_item' => __('Add New Event'),
           'edit_item' => __('Edit Event'),
           'new_item' => __('New Event'),
           'view_item' => __('View Event'),
           'search_items' => __('Search Events'),
           'not_found' =>  __('No Events found'),
           'not_found_in_trash' => __('No Events found in Trash'),
           'parent_item_colon' => ''
         );
   
         $supports = array('title', 'custom-fields', 'revisions');
   
         register_post_type( 'Event',
           array(
             'labels' => $labels,
             'public' => true,
             'supports' => $supports
           )
         );
       }
   
       // ------------------------- Slideshow -------------------------
   
       // Custom Post Type for Slideshow
   
       add_action( 'init', 'create_Slide' );
       function create_Slide() {
         $labels = array(
           'name' => _x('Slideshow', 'post type general name'),
           'singular_name' => _x('Slide', 'post type singular name'),
           'add_new' => _x('Add New', 'Slide'),
           'add_new_item' => __('Add New Slide'),
           'edit_item' => __('Edit Slide'),
           'new_item' => __('New Slide'),
           'view_item' => __('View Slide'),
           'search_items' => __('Search Slides'),
           'not_found' =>  __('No Slides found'),
           'not_found_in_trash' => __('No Slides found in Trash'),
           'parent_item_colon' => ''
         );
   
         $supports = array('title', 'custom-fields', 'revisions');
   
         register_post_type( 'Slide',
           array(
             'labels' => $labels,
             'public' => true,
             'supports' => $supports
           )
         );
       }
   
       // ------------------------- Boards -------------------------
   
       // Custom Post Type for Boards
   
       add_action( 'init', 'create_Boards' );
       function create_Boards() {
         $labels = array(
           'name' => _x('Boards', 'post type general name'),
           'singular_name' => _x('Boards', 'post type singular name'),
           'add_new' => _x('Add New', 'Board'),
           'add_new_item' => __('Add New Board'),
           'edit_item' => __('Edit Board'),
           'new_item' => __('New Board'),
           'view_item' => __('View Board'),
           'search_items' => __('Search Boards'),
           'not_found' =>  __('No Boards found'),
           'not_found_in_trash' => __('No Boards found in Trash'),
           'parent_item_colon' => ''
         );
   
         $supports = array('title', 'editor', 'custom-fields', 'revisions');
   
         register_post_type( 'Board',
           array(
             'labels' => $labels,
             'public' => true,
             'supports' => $supports
           )
         );
       }
   
       // Meta Data for Boards
   
       $key = "key";
       $meta_boxes = array(
   
       	"name" => array(
       	"name" => "name",
       	"title" => "Name",
       	"description" => ""),
   
       	"camber" => array(
       	"name" => "camber",
       	"title" => "Camber",
       	"description" => ""),
   
       	"shape" => array(
       	"name" => "shape",
       	"title" => "Shape",
       	"description" => ""),
   
       	"contruction" => array(
       	"name" => "construction",
       	"title" => "Construction",
       	"description" => ""),
   
       	"good" => array(
       	"name" => "good",
       	"title" => "Good In",
       	"description" => ""),
   
       	"flex" => array(
       	"name" => "flex",
       	"title" => "Flex",
       	"description" => ""),
   
       	"price" => array(
       	"name" => "price",
       	"title" => "Price",
       	"description" => ""),
       );
   
       	function create_meta_box() {
       	global $key;
   
       		if( function_exists( 'add_meta_box' ) ) {
       		add_meta_box( 'new-meta-boxes', ucfirst( $key ) . ' Custom Post Options', 'display_meta_box', 'Board', 'normal', 'high' );
       		}
       	}
   
       	function display_meta_box() {
       	global $post, $meta_boxes, $key;
   
       ?>
   
       <!-- Needed for Boards Meta Data -->
   
       <div class="form-wrap">
   
       <?php
   
       		wp_nonce_field( plugin_basename( __FILE__ ), $key . '_wpnonce', false, true );
   
       		foreach($meta_boxes as $meta_box) {
       		$data = get_post_meta($post->ID, $key, true);
       		?>
   
       		<div class="form-field form-required">
   
                   <label for="<?php echo $meta_box[ 'name' ]; ?>"><?php echo $meta_box[ 'title' ]; ?></label>
                   <input type="text" name="<?php echo $meta_box[ 'name' ]; ?>" value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>" />
                   <p><?php echo $meta_box[ 'description' ]; ?></p>
   
       		</div>
   
       <?php } ?>
   
       </div>
   
       <?php
       }
   
       function save_meta_box( $post_id ) {
       global $post, $meta_boxes, $key;
   
       	foreach( $meta_boxes as $meta_box ) {
       	$data[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
       	}
   
       	if ( !wp_verify_nonce( $_POST[ $key . '_wpnonce' ], plugin_basename(__FILE__) ) )
       	return $post_id;
   
       	if ( !current_user_can( 'edit_post', $post_id ))
       	return $post_id;
   
       	update_post_meta( $post_id, $key, $data );
       	}
   
       	add_action( 'admin_menu', 'create_meta_box' );
       	add_action( 'save_post', 'save_meta_box' );
   
       ?>
   
       <!-- Events Data -->
   
       <?php
   
       $key_event = "key";
       $meta_boxes = array(
   
       	"name" => array(
       	"name" => "event",
       	"title" => "Event",
       	"description" => ""),
   
       	"camber" => array(
       	"name" => "startdate",
       	"title" => "Start Date",
       	"description" => ""),
   
       	"shape" => array(
       	"name" => "enddate",
       	"title" => "End Date",
       	"description" => ""),
   
       	"contruction" => array(
       	"name" => "location",
       	"title" => "Location",
       	"description" => ""),
       );
   
       function create_event_meta_box() {
       global $key_event;
   
       if( function_exists( 'add_meta_box' ) ) {
       add_meta_box( 'new-meta-boxes', ucfirst( $key_event ) . ' Custom Post Options', 'display_meta_box', 'Event', 'normal', 'high' );
       }
       }
   
       function display_event_meta_box() {
       global $post, $meta_boxes, $key_event;
       ?>
   
       <div class="form-wrap">
   
       <?php
       wp_nonce_field( plugin_basename( __FILE__ ), $key_event . '_wpnonce', false, true );
   
       foreach($meta_boxes as $meta_box) {
       $data_event = get_post_meta($post->ID, $key_event, true);
       ?>
   
       <div class="form-field form-required">
       <label for="<?php echo $meta_box[ 'name' ]; ?>"><?php echo $meta_box[ 'title' ]; ?></label>
       <input type="text" name="<?php echo $meta_box[ 'name' ]; ?>" value="<?php echo htmlspecialchars( $data_event[ $meta_box[ 'name' ] ] ); ?>" />
       <p><?php echo $meta_box[ 'description' ]; ?></p>
       </div>
   
       <?php } ?>
   
       </div>
       <?php
       }
   
       function save_event_meta_box( $post_id ) {
       global $post, $meta_boxes, $key_event;
   
       foreach( $meta_boxes as $meta_box ) {
       $data_event[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
       }
   
       if ( !wp_verify_nonce( $_POST[ $key_event . '_wpnonce' ], plugin_basename(__FILE__) ) )
       return $post_id;
   
       if ( !current_user_can( 'edit_post', $post_id ))
       return $post_id;
   
       update_post_meta( $post_id, $key_event, $data_event );
       }
   
       add_action( 'admin_menu', 'create_event_meta_box' );
       add_action( 'save_post', 'save_event_meta_box' );
   
       ?>
       ```
   

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

 *  [mydanblog](https://wordpress.org/support/users/mydanblog/)
 * (@mydanblog)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/problem-with-functionsphp/#post-1839091)
 * I hesitate to answer, because this isn’t quite my cup of tea, so I could be wrong
   here. My hunch was that the problem is in your add_actions. Then I saw that you
   have this code in there twice:
 *     ```
       add_action( 'admin_menu', 'create_meta_box' );
       add_action( 'save_post', 'save_meta_box' );
       ```
   
 * I’m new to hooks and add_actions – but if I guess correctly, you only need those
   once.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 5 months ago](https://wordpress.org/support/topic/problem-with-functionsphp/#post-1839205)
 * > Warning: Cannot modify header information
 * often caused by any characters (spaces, empty lines, etc) either before the first`
   <?php` or after the closing `?>` in functions.php
 * a forum search with the error text should give you more answers
 *  [WraithKenny](https://wordpress.org/support/users/wraithkenny/)
 * (@wraithkenny)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/problem-with-functionsphp/#post-1839442)
 *     ```
       function save_meta_box( $post_id ) {
       global $post, $meta_boxes, $key;
   
       	foreach( $meta_boxes as $meta_box ) {
       	$data[ $meta_box[ 'name' ] ] = $_POST[ $meta_box[ 'name' ] ];
       	}
   
       	if ( !wp_verify_nonce( $_POST[ $key . '_wpnonce' ], plugin_basename(__FILE__) ) )
       	return $post_id;
   
       	if ( !current_user_can( 'edit_post', $post_id ))
       	return $post_id;
   
       	update_post_meta( $post_id, $key, $data );
       	}
       ```
   
 * Your error is here. The following is outside a function and the html comment 
   is printed when the plugin is loaded (to early for any output). None of this 
   should be outside of a function block.
 *     ```
       add_action( 'admin_menu', 'create_meta_box' );
       	add_action( 'save_post', 'save_meta_box' );
   
       ?>
   
       <!-- Events Data -->
   
       <?php
   
       $key_event = "key";
       $meta_boxes = array(
   
       	"name" => array(
       	"name" => "event",
       	"title" => "Event",
       	"description" => ""),
   
       	"camber" => array(
       	"name" => "startdate",
       	"title" => "Start Date",
       	"description" => ""),
   
       	"shape" => array(
       	"name" => "enddate",
       	"title" => "End Date",
       	"description" => ""),
   
       	"contruction" => array(
       	"name" => "location",
       	"title" => "Location",
       	"description" => ""),
       );
       ```
   

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

The topic ‘Problem with functions.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 4 participants
 * Last reply from: [WraithKenny](https://wordpress.org/support/users/wraithkenny/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/problem-with-functionsphp/#post-1839442)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
