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

Check if user is logged in when clicking certain links on certain pages

You might start by looking at the is_user_logged_in() pluggable function.

https://developer.wordpress.org/reference/functions/is_user_logged_in/

This is basically two lines:

$user = wp_get_current_user();
return $user->exists();

In your case, wrap the links inside the curly braces of a conditional.

if ( is_user_logged_in() ) {

    // link
}

Related Posts:

  1. Customize the “Available for back order” text for specific variation
  2. How to pass bloginfo(url) in a jquery
  3. If user has clicked link add class and store using PHP/WordPress
  4. Update $wpdb query with AJAX
  5. Restrict wordpress access to logged users only
  6. Infinite loop when logging out using custom login form
  7. Implement jQuery Smart wizard
  8. Menu not updating for logged in users after redirect
  9. Can’t make lazy load for my site, help!
  10. How to reload a php script, using AJAX and jQuery
  11. wp_ajax_ 400 Bad Request
  12. Woocommerce – if selected attribute term equals
  13. AJAX to add to cart multiple products woocommerce
  14. how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
  15. Change CSS Variable value in Theme Customizer Live Preview
  16. WordPress Slick Slider + Magnific Popup
  17. Using wp_editor() when not logged stopped working
  18. Issues adding Recaptcha v3 to WordPress Registration
  19. Display specific page if user signed in
  20. update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
  21. Show the subcategory name based on current product
  22. Change Login or Logout text based on status
  23. wp_set_object_terms returns 500 error when called through AJAX function
  24. Refresh page after login with litespeed cache
  25. How can i send id of the currently posted form data through json response in custom wordpress plugin?
  26. Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
  27. JQuery modal not loading video on popup, only displaying it after multiple reopenings
  28. How to create an Email Subscription input in WordPress?
  29. Redirect after login depending on the URL
  30. WordPress ajax filter returning all posts when it should be filtering by category
  31. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  32. Move Jquery.js to Footer
  33. Redirecting the lost password page request when using a custon login page
  34. getting the values of hidden inputs to use them in a php mysql query
  35. How do I send a POST request with params with WordPress REST API
  36. Remove specific javascript when viewing page in Customizer?
  37. Input field duplicates on form submit by jQuery
  38. Styling a specific post after hovering over it
  39. How to echo a PHP code into WooCommerce variation product?
  40. How can i get the same ajax result using WP REST API instead of admin-ajax?
  41. How to call a function from functions.php with ajax?
  42. wp-login.php?redirect_to=https problem
  43. Custom theme admin-ajax.php 400 (Bad Request)
  44. Remove item from post_meta array via AJAX
  45. is_user_logged_in() not working in homepage
  46. WordPress load javascript file if something… (after the page is loaded)
  47. include javascript Multiple files in wordpress through script.js
  48. Let user select the number of posts shown per page jquery error
  49. number of posts with “Load More”
  50. How to call WordPress PHP file using external js file
  51. PHP array to jQuery array ” Uncaught SyntaxError: Unexpected token < "
  52. Creating Log-In Page for backend server
  53. defined (‘ABSPATH’) false after AJAX post to other PHP-file
  54. Check if a user is logged into my WordPress site which is on a different server
  55. Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
  56. Is there a reason why my wordpress PHP page isn’t loading into my PHP template
  57. ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
  58. I was wondering if it’s possible to implement card.js on WordPress
  59. Find the method which AJAX GET calls
  60. Newbie question. Login/Registration. New PHP page
  61. AJAX Filter WHILE Loop not working WordPress
  62. Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
  63. Calling header from JavaScript file
  64. How to create a radio button to alt between settings in wp_options table
  65. Ajax not updating to database
  66. WordPress 404 when using AJAX to call php function
  67. wordpress ajax pagination
  68. WordPress AJAX load post metadata in modal
  69. how use php query in AJAX jquery
  70. Adding a sidebar to wp-login.php
  71. jQuery doesn’t work in my php snippet
  72. Using Custom Javascript and pHp to send email to myself when a user clicks on an input button but only works on Chrome, IE, and Micorosft Edge
  73. Ajax Load more CPT via shortcode
  74. Form not working as it should in WordPress, but in a normal HTML site it does
  75. Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
  76. Add a downloaded JS file to WordPress
  77. Submitting my form to the database and then redirecting to payment site
  78. Slider from different widgets
  79. Querying posts based off a jquery datepicker
  80. AJAX Not Working With WordPress Database properly
  81. List users in a dropdown for login
  82. How to call javascript function (jquery) in a shortcode?
  83. Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
  84. A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
  85. Pass the updated value of aid from form using ajax
  86. ajax form with multiple submit buttons and values
  87. How to run ajax in WordPress Post?
  88. 500 (Internal Server Error) of external php file
  89. Adding unique marketing messages between certain products whilst using isotope/Infinite Scroll
  90. Pass php to database in JQuery: With AJAX?
  91. Use jQuery and AJAX to get HTML
  92. How can I correctly POST to a WordPress page?
  93. Not logged in when using http
  94. No Authors for custom post type
  95. add bootstrap modal after login in wordpress
  96. Adding instant search to wordpress page
  97. Fatal error: Call to a member function get_results() on a non-object in on line 26
  98. Add php function into .js file (for tinyMCE button)
  99. White screen after login attempt
  100. Why this plugin is not working?
Categories PHP Tags jquery, login, php
Problem with loading images from child theme CSS file with relevant path
Make a custom loop inside single.php with pagination

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