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:
- wp_enqueue_script was called incorrectly
- Extract image from content and set it as the featured image
- Masking logout URL
- How can I tell if I’m on a login page? [duplicate]
- Is it possible to use a forgot password url filter?
- redirect wp-login.php to another page
- Edit the_content function
- Login using the password from protected pages
- Remove image from post_content on save_post
- How do I redirect upon login a specific user based on role?
- Make WordPress size and name images for Retina.js
- Logging in redirects to correct page but shows logged out content until forced refresh
- WordPress function/template tag to get first n words of the content
- Pinterest Integration Using functions.php
- Allowing SVG uploads in media uploader without plug-in
- Unable to get_the_content(); of a post in WordPress via AJAX
- Remove default user registration, login and subscriber profiles
- is_user_logged_in not working to redirect only logged out users
- Members only site – still need the lost password page accessible
- How to change login labels
- Automatically wrap multiple images in div
- How can I add text to all posts/pages/categories/homepage etc
- Display post shortcode content in the sidebar?
- How can I get my Script to work on the Login page?
- Login Redirect if Logged in from Specific Page
- Unable to login using username
- When a user logs in, how can they view the website instead of the admin menu?
- WordPress PHP Conflicting User Sessions
- Get User Login Data (date, time… )
- Registration Hooks don’t appear to be working
- Tags break custom Excerpt function
- Secondary Menu and Logged In Users
- Prevent WordPress Automatic Logout
- error at login page in wordpress
- Add Login/Logout Menu Item to Primary Nav “My Account” Submenu [Woocommerce] [closed]
- Logout Redirect and also WP-login.php Redirect
- loginout function customization
- Add Login and logout buttons to top menu bar
- Show errormessages on wrong username/password on custom loginform?
- the_excerpt function not showing image
- WordPress login set cookie that survive browser exit (wp_signon function)
- 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
- Prevent wp_signon redirect on failed login for ajax login
- How to redirect Subscribers on login to specific page, when logging in from a Page
- How to replace ACTION url from original wordpress login form?
- Unable to login after registration
- Allow logged in user to view a Page, else send to login screen and then redirect back to Page
- What is best practices to move the following code into a function?
- Redirect after login to current URL
- Regex works in regexr, but not if I filter content [closed]
- Login functions
- WordPress permanently logging users out
- Problem in outputting shortcode
- Problem in shortcode outputting content
- How to request login for user but not for bots
- is_user_logged_in() isn’t working
- update_user_option not working as expected
- “Headers already sent” while trying to add a CSS file to my login page?
- Integrating custom API for post content into Admin interface & Public Website [closed]
- Trying to get this function to show below the content
- Adding a second email address to a completed order in WooCommerce [closed]
- Advantages and disadvantages of using automatic-feed-links
- Is it possible to override this function/class in a child theme?
- Change meta tags programatically
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- Use a function to update post meta based on other post meta
- Adding body class when post contains a specific shortcode
- Displaying Widgets
- Display WooCommerce subscriptions for user [closed]
- How To Remove Duplicate Menu Locations
- Show top commenters without using a plugin
- How to get membership level for specific user email
- Post thumbnail not showing in WP admin area for custom post type
- Backstretch.js and thumbnail sizes to reduce loading time
- Child theme within a child theme?
- Featured Image Thumbnail Creation
- Updating Media Published Date When Parent Post Is Modified in WordPress
- WP Ajax Function Always Returning undefined
- How can I grab the video id of youtube?
- Passing variable as add_shortcode argument
- add_action wp_enqueue_script priority level only works for admins
- Is there a way to direct unregistered user to registration page when click a link?
- Auto log in hook is requiring a page refresh
- how to get the post ID from wp_insert_post
- The Capability to choose post/page template
- The_content and Preg_replace in loaded Iframe [closed]
- Add a mature content warning to first-time visitors
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- wordpress built-in Jalali date convertor
- WordPress Function Assistance with Loop
- Populate acf-field, depending on block name
- Add Change role button for list of user in an event
- I am trying to set post terms to a custom taxonomy
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- WordPress Javascript Widget jQuery Dependency Issue
- Allow tags and attributes in post and pages content
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function