Odd PHP Code To Display HTML Of Meta Box

I’m trying to use add_meta_box() to create meta information for my custom post type. So far it’s fine, but I don’t understand why the $callback looks the way it does.

An example from one tutorial is this:

/* Display the post meta box. */
function callback( $post ) { ?>

  <?php wp_nonce_field( basename( __FILE__ ), 'smashing_post_class_nonce' ); ?>

    <label for="smashing-post-class"><?php _e( "Add a custom CSS class, which will be applied to WordPress' post class.", 'example' ); ?></label>
    <br />
    <input class="widefat" type="text" name="smashing-post-class" id="smashing-post-class" value="<?php echo esc_attr( get_post_meta( $post->ID, 'smashing_post_class', true ) ); ?>" size="30" />
<?php }

What’s up with ?> (in line two) and <?php} (in the last line)? I don’t understand.

Can I just echo out HTML instead of doing that?

Read more here: Odd PHP Code To Display HTML Of Meta Box

Leave a Reply

Your email address will not be published. Required fields are marked *