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

how to protect wordpress website

In the header.php of your theme you can add the following code @ the beginning of the php code

if ( is_user_logged_in() ) {
  header( 'Location: /' );
} else {
  header( 'Location: /wp-login.php' );
}

If the user is not logged it will be redirected to the login form else it will be redirected to the /home page or tha page u want.

Related Posts:

  1. How to add field for new site-wide option on Network Settings screen?
  2. Correct way to serialize the data of options table?
  3. Where should I use get_option in a plugin
  4. How to tell if plugin has been network activated
  5. Custom plugin settings: clicking “save changes” does not display success message
  6. How to get user-meta from Social Login registered users?
  7. Duplicate settings of master blog to slave blogs in WP multi-site installation
  8. Environment Specific Options Token
  9. How do I extract the Alt Text from an image attachment upload via the WordPress Options Framework Plugin?
  10. Tracking last login and last visit
  11. How to fetch serialized data from wordpress options
  12. Some Plugin Settings Are Kept After Removal and Reinstall of the Plugin
  13. Changing widget options via the functions.php when there are no hooks
  14. While Using Static Pages, How Can I Get /blog into the URL of Each Post?
  15. Prevent Brute Force Attack
  16. Login with email (WP Modal Login)
  17. Check if the front end user is log in or not
  18. Get all options saved by another plugin
  19. Is it ok to call get_option without hooks?
  20. Enable/Disable WP options programmatically
  21. add function to saving change on Options Pages
  22. clean wp_options table unused rows
  23. How to set CORS header?
  24. Prepare plugin options for multi-lingual support
  25. Creating a plugin that will add options. Where should the options menu pages go?
  26. wp_authenticate but not logged in
  27. update_user_meta add value on the top on existing value
  28. Set the active Navigation Menu from a plugin
  29. Serialize data for wp options
  30. How do i login when i cant access wp-login.php?
  31. How to add a default value to get_option if it’s used as a variable?
  32. Single central login for front end users from any site
  33. WordPress get_option and update_option returned entered on the textbox field
  34. Plugin: Google Analytics for Dashboard error – Timestamp is too far from current time
  35. How to save generated JWT token to cookies on login?
  36. changes to widget settings not showing up in individual pages pages until they’re updated [closed]
  37. Show admin notice on incorrect value on form field
  38. How to remove traces from widget during uninstallation
  39. php page not found for plugin options menu
  40. add tabs in rdp-plugin/includes/settings.php and get settings saved
  41. options creation for plugins
  42. get_option error plugin development
  43. WordPress error: Options page Setting_ not found in the allowed options list
  44. Change wp-login to custom URL login page
  45. Allowed memory size exhausted problem
  46. Plugin getting Cannot modify header information errors
  47. Saving widget options from class method
  48. Get ‘Headers already sent’ error for the plugin I am creating when I try to login
  49. Theme My Login Shortcode Doesn’t Return Anything
  50. OceanWP settings are missing from Add New Post [closed]
  51. Possibility to login without password
  52. Plugin scheduled event not working
  53. WordPress unable to write files in the server
  54. Store plugin page content in wp_options?
  55. How to make a textarea accept javascript in my settings apge?
  56. How do you add a settings page to another menu?
  57. How to get values from network settings panel?
  58. How to add a custom form to a plugin’s setting page
  59. update_option creates an option, which empties on a blog reload
  60. How to make sure settings are not lost when plugin is updated?
  61. Linking form to user meta fields
  62. WordPress Multisite Profile Picture Sync Error with Nextend Social Login Plugin
  63. Plugin or ways to limit number of users logging in the website,
  64. how to show new field if option selected?
  65. Problem with MEMCACHE and Redis with wp_options
  66. Changing the CSS with a plugin
  67. Which membership plugin for a simple sign in? Personal areas for customers
  68. Login/password protected “client page”
  69. WordPress Admin login redirect to homepage
  70. On button click, redirect users to registration page instead of another page
  71. How to show private pages based on a user’s role?
  72. Optimized PHP & WordPress settings for speed/performance?
  73. WP options plugin setting not saving the selected checkboxes
  74. Enable plugins that are “not supported”
  75. Registered sidebar area is not shown from plugin.
  76. Why is the WordPress update_option not working in this code?
  77. wp_login_form() ignoring login_form action hook
  78. WordPress update plugin through Dashboard/Plugins displaying error
  79. Auto-login from backend
  80. Option page not updating multiple records in settings api
  81. get_option returning old value for non-admin users
  82. wp-admin will not redirect to wp-login.php
  83. Validating values using Settings API?
  84. Adding google authenticator and use only email address of user
  85. get Options value in “external” page
  86. homepage olderposts link showing page not found
  87. WordPress ReAuth =1 Loop with wpCAS
  88. WP e-commerce sales-view
  89. My first plugin doesn’t save the data in options
  90. Advice on setting up private site
  91. Checking url from plugin [duplicate]
  92. Change All Login/Signup Links in Plugin
  93. plugin for different writers [closed]
  94. selecting options from another form
  95. How to resolve these findings from security audit
  96. ERROR: Cookies are blocked due to unexpected output – no access to FTP
  97. How to Find WordPress site has backdoor login Codes
  98. How to create a custom wordpress plugin for a specific functionality?
  99. How to access values from your own settings page in javascript?
  100. How to fix a Wordfence scan that doesn’t finish?
Categories plugins Tags login, options, plugins
Add custom content to nonexistent page
Can figure out how to get wordpress to go .com not .com/directory

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