Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created January 17, 2016 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/bacd4d26ba994ed7085e to your computer and use it in GitHub Desktop.
Save billerickson/bacd4d26ba994ed7085e to your computer and use it in GitHub Desktop.
<?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