Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created July 10, 2017 22:38
Show Gist options
  • Save rafaehlers/369332518f68c9861680c10386b6b340 to your computer and use it in GitHub Desktop.
Save rafaehlers/369332518f68c9861680c10386b6b340 to your computer and use it in GitHub Desktop.
Strip the first word only of a string
add_shortcode( 'gv_wordstrip', 'gv_wordstrip' );
function gv_wordstrip( $atts ) {
global $gravityview_view;
extract($gravityview_view->field_data); // create a $entry variable with current entry data array
extract( shortcode_atts(
array(
'field_id' => '',
), $atts )
);
$word = $entry[$field_id];
if (empty($word)) {
return 'Error: No field ID specified.';
}else{
$firstword = substr($word, 0,1);
}
return $firstword;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment