Link Picker control designed to work with CMB2.
Using the Link Picker for CMB2 control, you can choose a link from your WordPress site, or manually enter a link. You can also identify if the link should open in a new window, or not.
Features:
link_picker
repeatable
is set to true
text
, url
and blank
when using get_post_meta
split_values
to true
. You can retrieve the split values by using the ID of the field and appending _text
, _url
and _blank
to the ID when using get_post_meta
(not compatible if using a repeatable field)See usage examples under Installation.
link-picker-for-cmb2
link-picker-for-cmb2
folder to the /wp-content/plugins/
directoryExample metabox:
$cmb->add_field( array(
'name' => __( 'Website URL', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'url',
'type' => 'link_picker',
'repeatable' => true,
'split_values' => true // default is false
) );
Example display:
$url = get_post_meta( get_the_ID(), '_yourprefix_url', true );
if ( 'true' === $url[0]['blank'] ) {
$blank = ' target="_blank"';
} else {
$blank = '';
}
printf(
'<a href="https://github.com/mattwatsoncodes/link-picker-for-cmb2/blob/master/%s"%s>%s</a>',
esc_url( $url[0]['url'] ),
$blank,
esc_html( $url[0]['text'] )
);
1.0.0 - 11.07.2016 - First stable release.
1.0.1 - 14.07.2016 - Media assets error message fix
1.0.2 - 14.07.2016 - Updated responsiveness of control
1.0.3 - 21.08.2016 - Fixed JS issues (with thanks to sagetopia)
1.0.4 - 21.08.2016 - Control now works if editor not supported by post type
1.0.5 - 23.09.2016 - Fixed a bug where the link was getting added to the main content editor
1.1.0 - 27.01.2017 - JS Error free for 2017! - Squashed all those nasty JS console bugs
1.2.0 - 27.01.2017 - WP Coding Standards, We got em! - Now passes those pesky WP Coding Standards
1.2.1 - 17.03.2017 - Added new artwork