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

If user is logged-in display/hide something

Your code won’t work in a themes functions file unless it includes a hook.

Try something like:

add_action( 'loop_start', 'your_function' );
function your_function() {

if ( is_user_logged_in() ) {
    echo '<li id="text-2" class="hide">';
} else {
    echo '<li id="text-2">'; 
}}

Related Posts:

  1. wp_enqueue_script was called incorrectly
  2. Extract image from content and set it as the featured image
  3. Masking logout URL
  4. How can I tell if I’m on a login page? [duplicate]
  5. Is it possible to use a forgot password url filter?
  6. redirect wp-login.php to another page
  7. Edit the_content function
  8. Login using the password from protected pages
  9. Remove image from post_content on save_post
  10. How do I redirect upon login a specific user based on role?
  11. Make WordPress size and name images for Retina.js
  12. Logging in redirects to correct page but shows logged out content until forced refresh
  13. WordPress function/template tag to get first n words of the content
  14. Pinterest Integration Using functions.php
  15. Allowing SVG uploads in media uploader without plug-in
  16. Unable to get_the_content(); of a post in WordPress via AJAX
  17. Remove default user registration, login and subscriber profiles
  18. is_user_logged_in not working to redirect only logged out users
  19. Members only site – still need the lost password page accessible
  20. How to change login labels
  21. Automatically wrap multiple images in div
  22. How can I add text to all posts/pages/categories/homepage etc
  23. Display post shortcode content in the sidebar?
  24. How can I get my Script to work on the Login page?
  25. Login Redirect if Logged in from Specific Page
  26. Unable to login using username
  27. When a user logs in, how can they view the website instead of the admin menu?
  28. WordPress PHP Conflicting User Sessions
  29. Get User Login Data (date, time… )
  30. Registration Hooks don’t appear to be working
  31. Tags break custom Excerpt function
  32. Secondary Menu and Logged In Users
  33. Prevent WordPress Automatic Logout
  34. error at login page in wordpress
  35. Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
  36. Logout Redirect and also WP-login.php Redirect
  37. loginout function customization
  38. Add Login and logout buttons to top menu bar
  39. Show errormessages on wrong username/password on custom loginform?
  40. the_excerpt function not showing image
  41. WordPress login set cookie that survive browser exit (wp_signon function)
  42. This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
  43. Prevent wp_signon redirect on failed login for ajax login
  44. How to redirect Subscribers on login to specific page, when logging in from a Page
  45. How to replace ACTION url from original wordpress login form?
  46. Unable to login after registration
  47. Allow logged in user to view a Page, else send to login screen and then redirect back to Page
  48. What is best practices to move the following code into a function?
  49. Redirect after login to current URL
  50. Regex works in regexr, but not if I filter content [closed]
  51. Login functions
  52. WordPress permanently logging users out
  53. Problem in outputting shortcode
  54. Problem in shortcode outputting content
  55. How to request login for user but not for bots
  56. is_user_logged_in() isn’t working
  57. update_user_option not working as expected
  58. “Headers already sent” while trying to add a CSS file to my login page?
  59. Integrating custom API for post content into Admin interface & Public Website [closed]
  60. Trying to get this function to show below the content
  61. Simple way to make most of my site private
  62. wp_login_form display no styled form
  63. Redirecting after login except for a specific page
  64. Missing feature image link function
  65. What’s the difference between home_url() and site_url()
  66. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  67. get_template_directory_uri pointing to parent theme not child theme
  68. How to customize the_archive_title()?
  69. remove empty paragraphs from the_content?
  70. What is the “with_front” rewrite key?
  71. Why use if function_exists?
  72. How to override parent functions in child themes?
  73. Add multiple custom fields to the general settings page
  74. Ajax call always returns 0
  75. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  76. How long does a deprecated function live in core?
  77. Solution to render Shortcodes in Admin Editor
  78. How to add a data attribute to a WordPress menu item
  79. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  80. remove_action on after_setup_theme not working from child theme
  81. plugins_url vs plugin_dir_url
  82. Remove type attribute from script and style tags added by WordPress
  83. How to run a function every 5 minutes?
  84. Best way of passing PHP variable between partials?
  85. Upload Multiple Files With media_handle_upload
  86. How to display custom field in woocommerce orders in admin panel?
  87. Adding fields to the “Add New User” screen in the dashboard
  88. Issues with title-tag and document_title_parts
  89. How do I get the current edit page ID in the admin?
  90. How to check if a user exists by a given id
  91. Why isn’t is_page working when I put it in the functions.php file?
  92. Add tags to the section via functions.php
  93. Add image size if page template
  94. How to create a custom order status in woocommerce!
  95. Remove Actions/Filters added via Anonymous Functions
  96. Adding a second email address to a completed order in WooCommerce [closed]
  97. How to load parent_theme functions.php before child_theme?
  98. How to load scripts/styles specific for a page
  99. Programatically add options to “add new” custom field dropdown
  100. Is there any global functions.php file which works for any theme?
Categories functions Tags content, functions, login
Prevent other versions of jquery from loading on static front page
Problem in exploding the_content to array

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