Question
How can I add "X-Frame-Options" header for my WordPress site?
Answer
- Navigate to the directory where WordPress is installed using cPanel / Home / Files / File Manager or via SSH.
Create a copy of the original
wp-config.phpfile using File Manager or the following command:# cp -v wp-config.php{,.$(date +%s).bak}
- Open the
wp-config.phpfile for editing using File Manager or your preferred command-line text editor (such asviornanofor example). Locate the following line in the
wp-config.phpfile:/* That's all, stop editing! Happy blogging. */Add the following line below the line mentioned in step 4.
header('X-Frame-Options: SAMEORIGIN');Note: The above function can be used to apply other headers besides
X-Frame-Optionsas well.- Save and close the
wp-config.phpfile. Use the
curlcommand to test if the header was added successfully:# curl -IL example.com
HTTP/1.1 301 Moved Permanently
Date: Tue, 13 Apr 2021 06:19:32 GMT
Server: Apache
X-Powered-By: PHP/7.4.1 6
X-Frame-Options: SAMEORIGIN
X-Redirect-By: WordPress
HTTP/1.1 200 OK
Date: Tue, 13 Apr 2021 06:19:37 GMT
Server: Apache
X-Powered-By: PHP/7.4.16
X-Frame-Options: SAMEORIGINNote: Replace the "example.com" placeholder with your actual domain name. You should see the header added via the
wp-config.phpfile (X-Frame-Options: SAMEORIGIN) in the output of thecurlcommand as shown in above example output.
Comments
0 comments
Article is closed for comments.