add_shortcode('show_name', 'generate_content');
When WordPress finds a [show_name]
shortcode tag in content, it runs the function that matches the second parameter, which in this case is generate_content
. Try renaming your show_name() function to be the same, like this:
add_shortcode('show_name', 'my_show_name_func');
function my_show_name_func() {
$current_user = wp_get_current_user();
$first_name = $current_user->user_firstname;
return $first_name;
}
Everything else looks like it will work though I didn’t test this. For more information on adding a shortcode see the WordPress documentation here:
https://codex.wordpress.org/Function_Reference/add_shortcode
Also, since you are using it within a php block in a template, you can simply use the php function by calling it directly. For the above example doing this in your template would also work:
... Hi <strong><?php echo my_show_name_func(); ?></strong> ...
Will have the same effect.
Since php functions can be accessed like this, it’s best to ‘name space’ your functions so they – being uniquely named – don’t conflict with another function one that uses the same name in another theme or plugin.
Happy coding!