Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Echo Text If User Is Logged in But NOT the Author of post

Try something like this in your template tags (or wherever in your theme):


function should_display_link() {
    $post = get_post();

    // Something went wrong, bail. (You should always have a post, in theory)
    if ( ! $post ) {
        return false;
    }

    $current_user = get_current_user_id();

    // Assuming only logged-in users can subscribe.
    if ( ! $current_user ) {
        return false;
    }

    return absint( $post->post_author ) !== absint( $current_user );
}

In your template, you can use it like this:

<?php if ( should_display_link() ) : ?>
    <!-- Your link code here -->
<?php endif; ?>

Related Posts:

  1. WordPress: How to get the current logged in author page URL?
  2. Limit number of posts a user can make per minute?
  3. How do I retrieve a users’ last 5 posts?
  4. Cannot select certain authors for posts after import
  5. The post order is different for logged-in and non-logged-in users? [closed]
  6. Update post counts (published, draft, unattached) in admin interface
  7. How to Display a List of Users Who Have Made at Least 1 Post?
  8. How to protect pages with double authentication: password + email (in custom field)
  9. Hook that get’s triggered when the author of a post is changed
  10. Find out who deleted a page or post?
  11. the_author() returns empty string
  12. Prevent Authors from viewing each others Posts
  13. Display Random Author with Details in Sidebar
  14. How to show list of posts by author and category?
  15. How to add editor’s name to entry meta byline?
  16. Different permalink for posts and authors
  17. disable password protected page for logged users
  18. How to display posts by current user/author in a custom page template?
  19. Query posts distinct authors
  20. Force “Submit to review” when a post is updated
  21. Restrict the Number of Posts an Author can Publish (over time)?
  22. Search posts by post author name
  23. Get the user type of an author
  24. Show the title of the latest post by author
  25. Find most recent authors
  26. Show author post count in sidebar – Variable
  27. Get current users post URL?
  28. Get the author of the latest revision
  29. Filter posts by author and category simultaneously
  30. Custom Post Type & Author not associating, user post count is 0, api doesn’t return author in post objects
  31. Is it possible to show a different WP menu when using password protected pages?
  32. Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
  33. Overview with latest edited posts and pages
  34. Navigation link to specific user page
  35. Get how many days since last post of the current user
  36. Post author is changed to admin after his post is modified by admin
  37. Hide comments awaiting moderation from user who submitted the comments
  38. Get all posts by post_author
  39. Where is the “ancestors” post object attribute?
  40. Query All users that has post
  41. How can I control multiple editing of wordpress posts?
  42. Multiple authors for single post without plugin
  43. How do I allow users to follow a post and then allow admins to email all users who have followed that post?
  44. wp_insert_post let users post to without login…broke
  45. Authors in menu, template list post by author
  46. Get user’s most published categories
  47. Show the author’s count of total amount of posts assign to a custom taxonomy term
  48. Author must complete profile info before they can publish a post?
  49. Allow anonymous users to post to my site for moderation
  50. WP rest api returns 404 only when author param is used
  51. How can I list random authors from current post category?
  52. disable column on post and user list
  53. how to find user ids of all commenters in a post
  54. How to list users and their post amount?
  55. Is there any way to allow users to access content before it’s published?
  56. UberMenu list current user’s posts as menu items
  57. Create post for every user?
  58. How can I show wordpress posts based on author?
  59. Show info to author only
  60. count the total number of comments the user has received for his published posts
  61. Auto “expire” all of an authors posts on spcific date
  62. How to get the user meta data for a post?
  63. Limit posts per author role (excluding admin) in home page
  64. Guest Author – How to display posts on /author/ archive page
  65. Restrict users post for himself
  66. How can I show many posts an author has per week?
  67. How to give capability (publish contributors posts) to author role?
  68. How to allow logged in users to post anonymously
  69. Allow public to post on blog
  70. current post with current author
  71. Whitelist Author of Private Post
  72. How to build a site with a map that shows where people offer and need help?
  73. How to verify wp user password by sql query in wp? [closed]
  74. Show posts by a custom post author
  75. How can i delay reading posing in 3days for not logined user?
  76. Encountering “Wrong nonce. Action prohibitied.” when trying to alter User Role and unable to Post via WP Admin
  77. Getting the current author (it has changed) of a post, not the original author
  78. Users problem (multi-author plus multisite)
  79. Hightlight unread posts or new posts since last login
  80. Showing author page if user has no post
  81. Display Notification Bar on Header on Certain Post Count
  82. How do I manage my users post before publish?
  83. Gather posts into a cart/lightbox and share with another user
  84. obtain the author id given the post id
  85. Show comment number per author per day
  86. Get all comments of author’s posts
  87. (solved) getting post author’s user role
  88. Change all author links in Blog roll
  89. Display author’s name and avatar in post’s sidebar
  90. Assign published posts to another user automatically
  91. Add field to user meta table in database when link is clicked
  92. Hide comments and posts posted by other user
  93. Automatically create a default set of posts for each new registered user
  94. static landing page leading to author specific pages w/ “live” content
  95. If contributor has published 2 or more posts then show otherwise hide
  96. All Posts Linking to Author Posts directly
  97. Summary of Posts by an User
  98. Change post author without using wp_update_post()
  99. Display a list of users who have viewed the post you are viewing
  100. Is it possible to lock all new and existing WordPress posts to one specific author?
Categories posts Tags author, debug, login, posts, users
Help me to intergrate product database to WordPress
single post showing blank page in custom template

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress