Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Created May 12, 2016 18:00
Show Gist options
  • Save ronalfy/6987bdb361299ba52b4dfee9dffa6299 to your computer and use it in GitHub Desktop.
Save ronalfy/6987bdb361299ba52b4dfee9dffa6299 to your computer and use it in GitHub Desktop.
Custom H1 for CMB2
<?php
function nest_custom_title( $post_id = 0, $before = '', $after = '', $echo = true ) {
if ( 0 == $post_id ) {
$post_id = get_the_ID();
}
ob_start();
echo $before;
$title = get_post_meta( $post_id, '_custom_h1', true );
if ( false == $title || empty( $title ) ) {
echo esc_html( get_the_title( $post_id ) );
} else {
echo esc_html( $title );
}
echo $after;
$title = ob_get_clean();
if ( $echo ) {
echo $title;
} else {
return $title;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment