Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@h@ this part goes into functions.php
- // 'Custom Meta Title' field below post/page editor
- add_action('admin_menu', 'custom_meta_title');
- add_action('save_post', 'save_custom_meta_title');
- function custom_meta_title() {
- add_meta_box('custom_meta_title', 'Add meta title <small>(if left empty, blabla)</small>', 'custom_meta_title_input_function', 'post', 'normal', 'high');
- add_meta_box('custom_meta_title', 'Add meta title <small>(if left empty, blabla)</small>', 'custom_meta_title_input_function', 'page', 'normal', 'high');
- }
- function custom_meta_title_input_function() {
- global $post;
- echo '<input type="hidden" name="custom_meta_title_input_hidden" id="custom_meta_title_input_hidden" value="'.wp_create_nonce('custom-meta-title-nonce').'" />';
- echo '<input type="text" name="custom_meta_title_input" id="custom_meta_title_input" style="width:100%;" value="'.get_post_meta($post->ID,'_custom_meta_title',true).'" />';
- }
- function save_custom_meta_title($post_id) {
- if (!wp_verify_nonce($_POST['custom_meta_title_input_hidden'], 'custom-meta-title-nonce')) return $post_id;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id;
- $customMetatitle = $_POST['custom_meta_title_input'];
- update_post_meta($post_id, '_custom_meta_title', $customMetatitle);
- }
- @@h@ this part goes into header.php to replace the <title>....</title> section
- <title><?php
- if( is_single() || is_page() ) :
- $text = get_post_meta($post->ID,'_custom_meta_title',true);
- if( $text ) :
- echo esc_attr( $text );
- else :
- wp_title( '|', true, 'right' ); //default if no custom field input
- endif;
- else :
- wp_title( '|', true, 'right' ); //any other than single post or page
- endif; ?></title>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement