Adding custom fields in wordpress posts, or pages without using plugin

add_action( ‘add_meta_boxes’, ‘shorcodeslider’ );
function shorcodeslider() {
add_meta_box( ‘custom-srt-id’, ‘Slider shortcode’, ‘shorcodeslider2’, ‘post’, ‘normal’, ‘high’ ); // change post type here
}
function shorcodeslider2( $post ) {
$values = get_post_custom( $post->ID );
$text = isset( $values[‘custom-srt-text’] ) ? esc_attr( $values[‘custom-srt-text’][0] ) : ”;
?>
<input type=”text” name=”custom-srt-text” id=”custom-srt-text” value=”<?php echo $text; ?>” />
<?php
}
add_action( ‘save_post’, ‘shortcode_save’ );
function shortcode_save( $post_id ) {
if( isset( $_POST[‘custom-srt-text’] ) )
update_post_meta( $post_id, ‘custom-srt-text’, $_POST[‘custom-srt-text’] );
}

 

Shortcode to call the value:

<?php echo get_post_meta(get_the_ID(), ‘custom-srt-text’, true); ?>

 

Deatils:

Using wordpress “postmeta” table storing values from custom fields as:

update_post_meta( $post_id, ‘custom-srt-text’, $_POST[‘custom-srt-text’]);

 

Reference : http://wordpress.stackexchange.com/questions/104896/add-input-field-to-pages-edit-page-through-functions-php