in my multi author website I have a button that users can upload their avatars. I need to display this button in author page. I can do it. I added this button to author page. The problem is that author can see this button in other author's page too . That's why I need to display this button in author page of current user. I am so sorry I have no any reference code. I have no any idea how to do it. please help. Thank you for you attention. how to code that if current author page belongs to current user
-
2Please add the code you're using to the question.– HimadCommented Jun 3, 2022 at 17:24
-
@himad sorry. I have no idea how to do this thats why sorry . no code– Teymur AbbasovCommented Jun 3, 2022 at 17:31
-
You mentioned you managed to add the button to all author pages. Can you add that code here?– HimadCommented Jun 3, 2022 at 17:32
-
@Himad I added to code into topic. This is just a shorcode. I use it in header for logged in users– Teymur AbbasovCommented Jun 3, 2022 at 17:37
Add a comment
|
1 Answer
The is_author()
conditional can be used to check if the query is targeting an author's page. By passing one or more User IDs/nicenames into it, it will check for specific author pages. So to check if the current author page is for the current user, it can be passed the return value from get_current_user_id()
:
if ( is_user_logged_in() && is_author( get_current_user_id() ) ){
echo "belongs to current user ";
}
else {
echo "not belongs to current user";
}
-
1Excellent! An even simpler way to write this is
is_author(get_current_user_id())
– boscoCommented Jun 3, 2022 at 18:27 -
@bosco thank you. I would be grateful if you improve my code with your answer. How to apply is_author(get_current_user_id()) Commented Jun 3, 2022 at 18:37
-
@bosco thank you very much. really your way is better Commented Jun 3, 2022 at 18:57
-
1It's really pretty much performing the exact same check that you were doing manually - just with a little less typing :)– boscoCommented Jun 3, 2022 at 18:59