How to add logged in username after wordpress url?

Question

I found a great solution for this issue in this article:
How to add wordpress username after url?

/*
Plugin Name: My Awesome Button
Description: The shortcode [my-awesome-button] will be replaced with the HTML code for a button for logged-in users and for guests it will be replaced with an empty string (so it will be removed). This will work for posts and pages.
Author: Nikolay Nikolov
Version: 1.0.0
*/

add_filter( ‘the_content’, ‘my_awesome_button_function’, 99999999999 );

function my_awesome_button_function( $content ) {
if ( strpos( $content, ‘[my-awesome-button]’ ) !== false ) {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$button_html = ‘user_login ) . ‘”>Click me’;
$content = str_replace( ‘[my-awesome-button]’, $button_html, $content );
} else {
$content = str_replace( ‘[my-awesome-button]’, ”, $content );
}
}
return $content;
}

My only problem, that the button is active only on the homepage and inactive on all of the other pages on the website (for example mydomain.com/documents).

Please be so kind and help me to fix it.

Thank you very much!

0
, Andrea Hugyak 3 years 2020-06-05T09:11:09-05:00 0 Answers 95 views 0

Leave an answer

Browse
Browse