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

change div text and link for logged in users

You can use the session functionality in PHP to determine if a user is logged in or not.

<?php
session_start();

if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) {
  $link = '/my-account.php';
  $text="My Account";
} else {
  $link = '/login.php';
  $text="Login";
}
?>
<a href="<?php echo $link; ?>"><?php echo $text; ?></a>

Related Posts:

  1. Login to wordpress by clicking a link and specifying usernaname and password in url
  2. Programmatic Login from 3rd Party site
  3. Use DOMDocument with ob_start breaks my HTML code
  4. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  5. How to change redirection route to a php page for making it only accessible by logged-in members?
  6. How to debug my custom login form looping intermittently
  7. getting logged in user info (wp-load.php) from parent directory
  8. selected option if current category is the value
  9. How to remove ?wp-mce-4103-20162941
  10. Customize position of social icons in upme plugin [closed]
  11. Why Won’t My Inputs in a form with a Get method work together?
  12. parts of url disappear when using # inside href=”” [closed]
  13. Settings API callback function inserts html quotes from nowhere
  14. Input data from email form not going to JSON file
  15. How to get the value of input hidden html from text editor to custom page template?
  16. Different post styles depending on category
  17. How create a Shortcode with hover and complex options
  18. How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
  19. Dot is not added at the end of href
  20. WordPress Multiple Navigation bars
  21. Position banner to right of logo in header – messed up my header file
  22. Commenting out unwated CSS/scripts in HTML with PHP
  23. Are all hooks/functions tied to Kses meant for sanitization?
  24. How to separate HTML and WordPress files
  25. Add .htm extention to a custom taxonomy
  26. Problem with login form
  27. Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
  28. How do I add a custom css to all posts without affecting homepage css? [closed]
  29. Make PHP work with HTML tags
  30. Log in / Log Out Custom Button
  31. Noscript not working as it should in wordpress site
  32. Show latest posts in a plain HTML website custom widget [closed]
  33. Should `wp_login` be used since it’s deprecated?
  34. How to convert select to HTML with PHP tags inside of it [closed]
  35. How to redirect users based on role and content of redirect_to?
  36. Change CSS based on is_user_logged_in
  37. Is this spyware on my site or a real Java update?
  38. Syntax error when I try to insert my loop into an unordered list? [closed]
  39. How to display login form anywhere, when user isn’t logged in, without redirecting?
  40. How can I open up my administrative panel to everyone?
  41. How to make modifications only to certain elements of an HTML string on the server-side?
  42. Wrapping a Sidebar within
  43. Search WordPress using static html page
  44. Hide HTML element (by class or ID) with PHP
  45. Add Codepen animation as Preloader to WordPress
  46. Path for php file for inserting data through html form
  47. Function returns text instead of html [closed]
  48. Printing HTML codes
  49. Widget back end radio button issue
  50. HTML escaping data with ajax requests
  51. How i can get post data from database when i am getting post id from url in wordpress
  52. How to retrieve the data from the sever and displaying it in a page?
  53. php within html within php
  54. How to execute html code inside php?
  55. How to remove coupon dropdown feature
  56. Add data-id attribute to child page links
  57. Add shortcode in my div
  58. Location of core code for database connection and get_header
  59. Adding a line of text to php code
  60. WordPress plug-in for dynamic download link?
  61. HTML table attributes ignored
  62. php esc_html_e with an html link inside not working
  63. Add html link in functions.php files of the theme
  64. Using ob_start and ob_get_clean with wordpress shortcode
  65. How to edit HTML of my website on WordPress? [closed]
  66. WordPress wp-admin redirect and exception
  67. How to remove the h6 tag for the entry-category Class
  68. Override user-edit.php to design own profile page
  69. How can I add a new row in a separate database when someone registers via WordPress?
  70. wp_insert_post() with HTML tags using PHP
  71. How to rename woocommerce-billing-fields
  72. Prevent redirect to wp-login.php
  73. PHP contact form not redirecting [closed]
  74. Creating an image from a custom field
  75. How to Schedule Cronjobs for start of every month and year
  76. Where can I find the inline-css of my theme header?
  77. Handling PHP/HTML inside the output of a shortcode function
  78. Make textarea required. Help [closed]
  79. One account with multiple logins
  80. Admin submenu issue with PHP not detecting two strings as equal
  81. Lost in trying to create user database system
  82. WordPress forms submissions and PHP files
  83. Trying to display text in a block in a plugin page
  84. Menu Custom Data Attributes
  85. How to add post meta in while loop?
  86. Adding function to child theme’s function.php
  87. Highlight the links without using dropdown
  88. Illegal string offset error in wordpress theme options textarea
  89. How to turn each phone number within the $content to a telephone link?
  90. Creating custom page template from existing PHP site
  91. Shortcode to log user into current URL
  92. wordpress site – using custom database and PHP
  93. How to use the checked() function to check for a non-empty var
  94. Calling function in loop causes repeat data
  95. Remove &nbsp from the_excerpt
  96. How do I access post_meta key with php?
  97. Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages
  98. Separate array output into a
  99. Website completely messes up when logging out
  100. Need help removing […] after excerpt
Categories PHP Tags core, html, login, php, text
‘wp_site_health_scheduled_check’ Causes Failure Of Other Scripts
Edit a page/post DB data?

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