Skip to content

Instantly share code, notes, and snippets.

@billerickson

billerickson/functions.php Secret

Created Jan 17, 2016
Embed
What would you like to do?
<?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
You can’t perform that action at this time.