Skip to content

Instantly share code, notes, and snippets.

@vishnusomanus
Created October 25, 2018 06:20
Show Gist options
  • Save vishnusomanus/220f4b6633a868abc479a20915b2c11d to your computer and use it in GitHub Desktop.
Save vishnusomanus/220f4b6633a868abc479a20915b2c11d to your computer and use it in GitHub Desktop.
function add_meta_boxes() {
add_meta_box(
'wpa-45985',
'Extra Options',
'wpa_meta_box_display',
'dzsrst_items',
'normal',
'high');
} add_action('admin_menu', 'add_meta_boxes');
function wpa_meta_box_display() {
global $post;
wp_nonce_field( 'wpa_45985', 'wpa_45985_nonce' );
$meta = get_post_meta($post->ID, 'wpa_45985', true);
$font_awesome = isset($meta[font_awesome]) ? $meta[font_awesome] : '';
$custom_link = isset($meta[custom_link]) ? $meta[custom_link] : '';
?>
<!-- function.php -->
<label>Font Awesome</label>
<input type="text" class="widefat" name="wpa_45985[font_awesome]" placeholder="fa fa-font" value="<?php echo $font_awesome; ?>"/>
<br>
<label>Custom Link</label>
<input type="text" class="widefat" placeholder="http://" name="wpa_45985[custom_link]" value="<?php echo $custom_link; ?>"/>
<?php
}
add_action('save_post', 'wpa_meta_box_save');
function wpa_meta_box_save($post_id) {
global $custom_meta_fields;
if ( ! isset( $_POST['wpa_45985_nonce'] ) ||
! wp_verify_nonce( $_POST['wpa_45985_nonce'], 'wpa_45985' ) )
return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (!current_user_can('edit_post', $post_id))
return;
update_post_meta($post_id,'wpa_45985',$_POST['wpa_45985']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment