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

Adding a sidebar to wp-login.php

Here is my hack to add content above the login form using the login_body_class filter…

add_filter('login_body_class','login_body_hack',999);
function login_body_hack($classes) {
    $classes[] = 'PLACEHOLDER';
    add_filter('attribute_escape', 'login_body_filter_hack',999,2);
    return $classes;
}

function login_body_filter_hack($safe_text, $text) {

    // add whatever you like content here
    $newcontent="<div id="contentwrapper">CONTENT</div>';

    $replace="">"; // closes the body tag early
    $replace .= $newcontent;
    // some tag to be closed, as suffixed with the original ">
    $replace .= '<img src="https://wordpress.stackexchange.com/questions/233457/javascript:void(0);" style="display:none;'; 
    $safe_text = str_replace('PLACEHOLDER',$replace,$safe_text);
    remove_filter('attribute_escape', 'login_body_filter_hack',999,2);
    return $safe_text;
}

Note however that “as is” this will the content to all “login” pages (register, reset, lost password etc.) not just the login form one, so further checks would be needed to handle those cases.

Related Posts:

  1. User registration followed by automatic login
  2. Adding “Remember Me” in custom login
  3. How to change the wp-login.php page title?
  4. How build a custom login/register form with error handling?
  5. Change the footer text on the login page
  6. Changing user_nicename
  7. WordPress 4 invalid username special charachters issue
  8. How to place login logout link on menu that redirects users back to current page?
  9. How to turn off redirection from ‘domain.com/login’ to ‘domain.com/wp-login.php’
  10. display most popular tags in two columns
  11. How to resolve error “Cookies are blocked due to unexpected output.”?
  12. Using a nonce in a Custom Login Form
  13. Constructing a custom login form using ajax
  14. automated tests as a user?
  15. dynamic sidebar not showing anything
  16. Remove username in emails or swap username for email
  17. woocommerce and is_user_logged_in() if not redirect to homepage
  18. Styling images coming from another blog
  19. sidebar isn’t showing, what’s wrong w/ this code?
  20. Check if user is logged in when clicking certain links on certain pages
  21. PHP If user is logged in & on home page redirect
  22. WordPress shows registration link for non logged users
  23. WordPress widget/sidebar dividers?
  24. Creating login session via CURL
  25. Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
  26. Admin username and password
  27. How to show a dynamic_sidebar if main content content’s height is > a set amount?
  28. Where do posts get the sidebar from?
  29. How to create a linked tag list in my sidebar
  30. Recovering WP Login Credintials in Code?
  31. Missing sidebar parameter “fix” – before_content
  32. Is it necessary to sanitize wp_set_password user input?
  33. WordPress custom login form using Ajax
  34. How to give new users two specific user role options upon WordPress user registration
  35. Wp-login appears White Screen, Error: Cannot modify header information
  36. How to: PHP Log Out Link?
  37. Login/logout in header
  38. Dynamic Sidebars & Echo
  39. Why is my cookie not unsetting upon logout? [closed]
  40. User management system similar to wordpress one?
  41. Programmatic Login from 3rd Party site
  42. Cannot access wp-admin/wp-login.php (WordPress backend) anymore, what could be wrong?
  43. How to debug my custom login form looping intermittently
  44. getting logged in user info (wp-load.php) from parent directory
  45. Child page menu in sidebar
  46. Theme developement – incative sidebars
  47. Problem with login form
  48. Login to wordpress by clicking a link and specifying usernaname and password in url
  49. Generate sidebar depending on height of post
  50. Log in / Log Out Custom Button
  51. if statement with is_active_sidebar()
  52. Should `wp_login` be used since it’s deprecated?
  53. How to redirect users based on role and content of redirect_to?
  54. Change CSS based on is_user_logged_in
  55. How to determine if the sidebar is empty? Or not active?
  56. How to display login form anywhere, when user isn’t logged in, without redirecting?
  57. How can I open up my administrative panel to everyone?
  58. Sidebar not appearing in footer, but it appears everywhere else!
  59. Styling the second sidebar
  60. Creating a blog on my companies new website using WordPress but I have sidebar issues
  61. How to remove sidebar primary widget on Mobile on category page [closed]
  62. How can I add a new row in a separate database when someone registers via WordPress?
  63. One account with multiple logins
  64. Lost in trying to create user database system
  65. Shortcode to log user into current URL
  66. Removing sidebar on category pages
  67. PHP getting error when trying to access WP-Admin Dashboard
  68. I installed WordPress locally now how do I login?
  69. If user is logged in not working
  70. Change homepage content if user is logged in – BuddyPress
  71. How can the searchform.php know if it’s used on a registered sidebar id ‘sidebar-1’ or ‘sidebar-2’?
  72. How to list categories by page id in wordpress
  73. List users in a dropdown for login
  74. how to run a php code in widget?
  75. Not logged in when using http
  76. add bootstrap modal after login in wordpress
  77. if conditional in sidebar plugin Password content shortcode
  78. White screen after login attempt
  79. My custom widget won’t stay in the widget area after I refresh the widget page
  80. how to remove sidebar from particular one page
  81. Listing current pages subp page in list items in the sidebar
  82. How to display different widgets on specific pages, hide from other pages
  83. Sidebar doesnt get updated?
  84. Redirect users not logged in to the standard login page (and back) from some posts and pages
  85. How to replace wp-admin login page to another location?
  86. Check user last login date
  87. Prevent users from display default wordpress login form
  88. login redirect based on user role not work as expected
  89. How to change wp-admin and wp-login urls
  90. How do I do so that people can register on my wordpress site?
  91. wp_login_url always redirects me to wp-admin
  92. I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”
  93. Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
  94. change div text and link for logged in users
  95. Sidebars panel in customizer
  96. wp-login – unable to redirect user to a custom login url
  97. Redirect to current URL and append specified URL parameter on unsuccessful login through Elementor login form widget
  98. change Dashboard default page on login
  99. Side bar only if it’s not a single post or a specific page
  100. Can’t programmatically log user in php
Categories PHP Tags login, php, sidebar
AJAX call in backend results in empty update_option
How can I add an “Attach image to this post/page” link on the Add Media lightbox?

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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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