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

Log in / Log Out Custom Button

here is a very simple function that should do it:

function loginout_button_wpa89153($echo = true){
    if (is_user_logged_in()){
        $url = wp_logout_url(get_permalink());
        $anchor = "Logout";
    }else{
        $url = wp_login_url(get_permalink());
        $anchor = "Login";
    }
    $button = '<a href="'.$url.'" class="join-button">'.$anchor.'</a>';
    if ($echo)
        echo $button;
    else
        return $button;
}

Related Posts:

  1. Change the footer text on the login page
  2. Copyright info change in Theme Child PHP
  3. Add footer.php to WordPress child theme
  4. Successful or Error Message after running mysql code in functions.php
  5. Login/logout in header
  6. getting logged in user info (wp-load.php) from parent directory
  7. How to display login form anywhere, when user isn’t logged in, without redirecting?
  8. Display Data in Table from External Database in WP using Shortcodes
  9. Need help for some PHP code
  10. Can’t log in to WordPress wp-admin after adding code to functions.php
  11. How to preload header logo image in WordPress? like what’s the code and where do I put it?
  12. Having trouble creating two shortcodes, one for logged in user and one for visitors
  13. How to put 2 php codes in functions.php without site crashing
  14. Restrict wordpress access to logged users only
  15. Menu not updating for logged in users after redirect
  16. how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
  17. Refresh page after login with litespeed cache
  18. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  19. is_user_logged_in() not working in homepage
  20. how to create twitter card without plugin in wordpress website?
  21. Change the WP Video Shortcode Output
  22. Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
  23. remove wp floating submenu in wp dashboard
  24. How to put “Read more” link in Custom Excerpt inside p tag?
  25. Two Different Links for Same Product – WooCommerce [closed]
  26. ACF: how do I get the fields and its values of a specific group?
  27. How to save checkbox values for logged in users?
  28. How to store data from multiple forms using ajax and php
  29. How to control WordPress image metadata (using Imagick)?
  30. How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
  31. Get value from shortcode to do something
  32. PHP 8, AJAX mail form to function.php doesn’t work
  33. How do I add custom bulk actions to multiple custom post types?
  34. Error when adding excerpt to the content through functions.php
  35. Automatically adding new post categories to menu
  36. Add data attribute to each li in menu
  37. Get post id in a function when edit/add a post
  38. Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
  39. How to check if a meta value has already been assigned to any user?
  40. How to complete two other input fields, completed the first
  41. Prev/Next child navigation for current page modifications?
  42. Adding rel tag to all external links
  43. How can I apply_filters from inside a function?
  44. function to assign user role based on a field from usermeta
  45. what is the best practice to add new field to an api route
  46. Retrieve $_POST data submitted from external URL in WordPress(NOT API)
  47. Programmatic Login from 3rd Party site
  48. Pass Category Name, Description and Photo into variables to pass to jQuery
  49. Use DOMDocument with ob_start breaks my HTML code
  50. Auto-update products after they were published – Woocommerce
  51. How to prevent WP_Query function from returning all posts when empty?
  52. wp_trim_words() does not work with my code Am I doing any mistake in my code?
  53. JS file work only in index page
  54. Display a specific category of products in shop page and disable code for specific actions
  55. Woocommerce related product text
  56. esc_html_e() is not translating string in wordpress [closed]
  57. Removing “wpautop” (auto tags) only on certain pages?
  58. Fatal error: Uncaught Error: Call to undefined function test()
  59. How to pick the default selected value in wordpress dropdown?
  60. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  61. Using WP-API and SSE not authenticating user ID
  62. Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
  63. Validate functions before inserting then into functions.php
  64. How to retrieve current wordpress profile page URL?
  65. Firing schema via code in functions.php doesn’t work
  66. A non-numeric value encountered in /wp-includes/functions.php on line 68
  67. Get page that displays all children of taxonomy parent
  68. Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
  69. get author_name from queried post
  70. How to debug my custom login form looping intermittently
  71. Why ajax doesn’t work on certain wordpress hooks?
  72. Is it possible to intercept all ajax requests and get the parameters and the returns?
  73. How to call plugin function per site in a multisite?
  74. Print last modified date only on posts
  75. different id for same element visual composer [closed]
  76. WooCommerce: How can I get orders with a custom ID in order meta data object?
  77. Tax query in pre_get_posts not working
  78. WordPress Gravatar filter is removing my custom attributes
  79. foreach loop still echoes array
  80. trigger html cleanup for all posts
  81. Error in custom php function doesn’t exist
  82. dynamic dependent select dropdown
  83. Generating an nonce for Content Security Policy and all scripts – How to make it match/persist for each page load?
  84. Custom shortcode outputs plain text instead of HTML at top of post
  85. how can i use $_COOKIE[] + PostID to execute the below code?
  86. Return a numerical function value in Customizer controls
  87. How can I get the values of my WordPress $wpdb query in Jquery?
  88. What’s the uses of wp_cache_set() or wp_cache_add()?
  89. Get users that likes the post
  90. Blog posts repeat
  91. Ajax load more button for comments wordpress
  92. Function to capture a value and store it in a variable
  93. How to abort saving data in save_extra_profile_fields function WordPress?
  94. Pass php dynamic variable to shortcode
  95. Unique icons next to each WordPress menu item
  96. 3 Slashes appear after Apostrophe in custom fields after updating product-site
  97. How to create a php variable using WordPress the_title() function
  98. Keyword checking in Gravity Forms
  99. how to refresh div on template part?
  100. Child page menu in sidebar
Categories PHP Tags code, functions, login, php
How to redirect just one or two blog posts correctly?
How to order posts in an arbitrary order?

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