admin管理员组文章数量:1333442
maybe u can help to solve this problem. for example i have this link
/?user=
and i want to add username after login, like /?user=admin
I want to make it on button.
<a href="/?user=username">
<button>Click me</button>
</a>
I want to put this on post / page.
maybe u can help to solve this problem. for example i have this link
https://direktoriku/shopping/?user=
and i want to add username after login, like https://direktoriku/shopping/?user=admin
I want to make it on button.
<a href="https://direktoriku/shopping/?user=username">
<button>Click me</button>
</a>
I want to put this on post / page.
Share Improve this question edited Apr 17, 2018 at 6:53 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Apr 17, 2018 at 3:20 Angga PradiptaAngga Pradipta 31 silver badge2 bronze badges2 Answers
Reset to default 0You can do
<?php
if( get_current_user_id() ): // check if user is loggedin
$current_user = wp_get_current_user(); //get user
?>
<a href="https://direktoriku/shopping/?user=<?php echo $current_user->user_login;?>
<button>Click me</button>
</a>
<?php endif;?>
This is a small plugin I made for you. Put this code in a php file and upload it as a plugin, and activate it. Then put the shortcode [my-awesome-button] in a post or page, and there it will appear the button. If the visitor is not logged-in, nothing will appear.
<?php
/*
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 = '<a href="https://direktoriku/shopping/?user=' . esc_attr( $current_user->user_login ) . '"><button>Click me</button></a>';
$content = str_replace( '[my-awesome-button]', $button_html, $content );
} else {
$content = str_replace( '[my-awesome-button]', '', $content );
}
}
return $content;
}
By the way, we can easily modify this to only show the username, not the whole button. This way you can put the username anywhere you want in the post or page. Let me know if you need help with that.
本文标签: usersHow to add wordpress username after url
版权声明:本文标题:users - How to add wordpress username after url? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742354572a2459155.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论