'Paste the user_login in the URL of a wordpress button
https://app.website.com/?user_login?
After nearly 15 years of reading your solutions.
Today it's my turn to ask help. I have a wordpress website, website.com site and an application app.website.com with bootstrap, when a user registers is on my site I use his unique user_login to create a space for him. I would like to create a "Dashboard App" button on my menu so that when he logs in, he just has to click it to go to app.website.com/user_login. But I can't find the solution. Currently I just manage to show him the link in his wordpress account like this :
<p>
<?php
printf(
'<strong>' . wp_kses( __( 'Otherwise, please login to your application here: <a href="https://app.website.com/%1$s/">app.website.com/%1$s/</a>', 'woocommerce' ), $allowed_html ) . '</strong>',
esc_html( $current_user->user_login )
);
?>
</p>
How can I put this link in a button in my menu?
Thank you in advance Best regard
Solution 1:[1]
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.com/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;
}
but it's work only on page. how to put it on a menu?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | aliskini france |
