Skip to content

Instantly share code, notes, and snippets.

@zackpyle
Created June 5, 2024 19:10
Show Gist options
  • Save zackpyle/2807d56b9f01f937b553e6816dc9bbf6 to your computer and use it in GitHub Desktop.
Save zackpyle/2807d56b9f01f937b553e6816dc9bbf6 to your computer and use it in GitHub Desktop.
Get First Name (aka first word in page title)
<?php
add_shortcode( 'first_name', 'get_first_name' );
function get_first_name() {
$title = get_the_title();
$full_name_seperate = explode( ' ', $title );
return $full_name_seperate[0];
}
@zackpyle
Copy link
Author

zackpyle commented Jun 5, 2024

Useful shortcode ([first_name]) when you have a post type of people (team, speakers, etc) and want to be able to use their first name without requiring a separate field to be input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment