WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a plugin that creates a custom post type I'm working on. I followed this tutorial. I have just changed it from movie_reviews to staff members. I don't get any syntax errors in PHP and it all looks alright, but when I activate the plugin in WordPress it says it generated 3 characters of unexpected output. I think the problem is the display_staff_member_meta_box function, but there doesn't appear to be any errors in it. Below is the code I'm using.

Plugin Name: Staff Members
Plugin URI: http://intranet.yourgroupuk.com
Description: Declares a plugin that will create a custom post type displaying staff members
Version: 1.0
Author: Harry Glozier
Author URI: http://intranet.yourgroupuk.com

function create_staff_member() {
    register_post_type( 'staff_members',
            'labels' => array(
                'name' => 'Staff Members',
                'singular_name' => 'Staff Member',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New Staff Member',
                'edit' => 'Edit',
                'edit_item' => 'Edit Staff Member',
                'new_item' => 'New Staff Member',
                'view' => 'View',
                'view_item' => 'View Staff Member',
                'search_items' => 'Search Staff Members',
                'not_found' => 'Staff Member not found',
                'not_found_in_trash' => 'No Staff Members found in Trash',
                'parent' => 'Parent Staff Member'

            'public' => true,
            'show_in_menu' => true,
            'menu_position' => 80,
            'supports' => array( 'title', 'editor', 'thumbnail', 'revisions' ),
            'menu_icon' => plugins_url( 'staff-icon-2.png', __FILE__ ),
            'exclude_from_search' => false,
            'has_archive' => true

function my_admin() {
    add_meta_box( 'staff_member_meta_box',
        'Staff Member Details',
        'staff_members', 'normal', 'high'

function display_staff_member_meta_box( $staff_member ) { //Causes error
    // Retrieve current Job Title and Company based on staff ID
    $job_title = esc_html( get_post_meta( $staff_member->ID, 'job_title', true ) );
    $company = esc_html( get_post_meta( $staff_member->ID, 'company', true ) );

    $table = <<<TEXT
            <td style="width: 100%">Job Title</td>
            <td><input type="text" size="80" name="staff_member_job_title" value="$job_title" /></td>
            <td style="width: 150px">Company</td>
                <select style="width: 200px" name="staff_member_company">
                    <option value="Your Group">Your Group</option>
                    <option value="Your Power">Your Power</option>
                    <option value="Your Electrical">Your Electrical</option>
                    <option value="Newmills Engineering">Newmills Engineering</option>
    echo $table;
} //End of function 

function add_staff_member_fields( $staff_member_id, $staff_member ) {
    // Check post type for staff members
    if ( $staff_member->post_type == 'staff_members' ) {
        // Store data in post meta table if present in post data
        if ( isset( $_POST['staff_member_job_title'] ) && $_POST['staff_member_job_title'] != '' ) {
            update_post_meta( $staff_member_id, 'job_title', $_POST['staff_member_job_title'] );
        if ( isset( $_POST['staff_member_company'] ) && $_POST['staff_member_company'] != '' ) {
            update_post_meta( $staff_member_id, 'company', $_POST['staff_member_company'] );

/* function include_template_function( $template_path ) {
    if ( get_post_type() == 'staff_members' ) {
        if ( is_single() ) {
            // checks if the file exists in the theme first,
            // otherwise serve the file from the plugin
            if ( $theme_file = locate_template( array ( 'single-staff_members.php' ) ) ) {
                $template_path = $theme_file;
            } else {
                $template_path = plugin_dir_path( __FILE__ ) . '/single-staff_members.php';
    return $template_path;
} */

add_action( 'init', 'create_staff_member' );
add_action( 'admin_init', 'my_admin' );
add_action( 'save_post', 'add_staff_member_fields', 10, 2);
//add_filter( 'template_include', 'include_template_function', 1 );
share|improve this question
up vote 1 down vote accepted

The unexpected output is the blank lines betwen ?> and <?php.

Avoid to close php tags and open them again with no reason. In your code, remove all the closing php tags (?>) and leave only the opening tag on first line.

share|improve this answer
Thanks a lot! I was not aware that would cause a problem, I only did it like that as I did it one function at a time. – Harry12345 Aug 4 '14 at 11:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.