ID; $sub = get_post_meta($post_id, 'the_sub_subtitle', true); if($sub != 'Subtitle'){ echo $sub; } } function get_the_subtitle($post_id = null){ if($post_id == null){ global $post; $post_id = $post->ID; } $sub = get_post_meta($post_id, 'the_sub_subtitle', true); if($sub != 'Subtitle'){ return $sub; } } function the_sub_shortcode(){ the_subtitle(); } // // Backend functions: // add_action( 'admin_enqueue_scripts', 'the_sub_style_register' ); add_action( 'edit_form_advanced', 'the_sub_form_register' ); add_action( 'edit_page_form', 'the_sub_form_register' ); add_action( 'save_post', 'the_sub_meta_save' ); function the_sub_style_register($hook) { if( $hook != 'edit.php' && $hook != 'post.php' && $hook != 'post-new.php' ) return; //add the styles and scripts: add_action('admin_head','the_sub_inline_style'); wp_enqueue_script('the_sub_script', the_sub_url().'/script.js', array('jquery'), '1.2', true); } function the_sub_inline_style(){ ?> ID; } //get the subtitle value (if set) $sub = get_post_meta($post_id, 'the_sub_subtitle', true); if($sub == null){ $sub = __('Subtitle'); } // echo the inputfield with the value. echo ''; } function the_sub_meta_save($post_id){ //check to see if this is an autosafe and if the nonce is verified: if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if (!isset($_POST['the_sub_nonce']) || !wp_verify_nonce( $_POST['the_sub_nonce'], plugin_basename( __FILE__ ) ) ) return; //update the postmeta accordingly: update_post_meta($post_id, 'the_sub_subtitle', $_POST['subtitle']); return; } function the_sub_url(){ //simple return function to get the URL of this plugin: $full_path = plugin_dir_url(__FILE__); return substr( $full_path , 0 , -1 ); //strip the trailing slash } ?>