Get first word from Wordpress page title

Solution 1:

If you still want to use the shortcode as the way to insert the title wherever you need it, then all you need is to combine the 2 functions above and insert it on the bottom of your functions.php file (preferably on a child theme).

 function first_word_from_title( ){
      $title = get_the_title(); // Retrieves the title
      $title_words = explode(' ', $title); // Transforms the title into an array composed of each separate word
      return $title_words[0]; // Returns the first element of the array
    }
  add_shortcode( 'page_title', 'first_word_from_title');

I don't think you need to worry about the above code causing a crash as it is only run when you insert the shortcode and not on every page load.

You can always test it first on a draft post and see if you get an error.