-
-
Save billerickson/bacd4d26ba994ed7085e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove "Page Links To" metabox | |
* | |
*/ | |
function be_remove_page_links_to() { | |
remove_meta_box( 'page-links-to', 'post', 'advanced' ); | |
} | |
add_action( 'do_meta_boxes', 'be_remove_page_links_to', 21 ); | |
/** | |
* Link Post Metabox | |
* | |
*/ | |
function be_link_post_metabox() { | |
// Register metabox | |
$metabox = new_cmb2_box( array( | |
'id' => 'be_link_post_metabox', | |
'title' => 'Post Link', | |
'object_types' => array( 'post' ), | |
'context' => 'normal', | |
'priority' => 'high', | |
'show_names' => true, | |
) ); | |
// Link field | |
$metabox->add_field( array( | |
'name' => 'Link', | |
'id' => '_links_to', | |
'type' => 'text', | |
) ); | |
} | |
add_action( 'cmb2_init', 'be_link_post_metabox', 9 ); | |
/** | |
* All links in new window | |
* | |
*/ | |
function be_links_in_new_window( $meta_value, $post_id, $meta_key, $single ) { | |
if( '_links_to_target' == $meta_key ) | |
$meta_value = true; | |
return $meta_value; | |
} | |
add_filter( 'get_post_metadata', 'be_links_in_new_window', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment