Useful .htaccess Tricks for WordPress

Useful .htaccess Tricks for WordPress

PHP Developers and WordPress developers some times comes across .htacess file.
this file is configuration file for for security and performance. here i will show few usefull tricks to do with .htacess file. This file is located at root of your website (/public_html/)

Before we start lets grab the .htacess file from FTP and keep one backup (Just for fail safe).
if you dont have any .htacess file in your root folder under public_html.

Protect

  1. Protect wp-config.php file
    1. It was most important to protect your wp-config file because it has all the information about your database. if anyone get this file they can easily connect to our data base. Here  is the code for protecting wp-config.php file
      <files wp-config.php>
      order allow,deny
      deny from all
      </files>
    2.  Protect wp-admin folder
      you can easly genarate login protect for wp-admin folder here is the link how to do it
      http://www.htaccesstools.com/htpasswd-generator/
Common WordPress Errors and How to Fix

Common WordPress Errors and How to Fix

  1. Syntax errors

This error usually occurs when you are trying to add code snippets into WordPress and have accidentally missed something or the code has incorrect syntax. This will result into a PHP parse error and you will see a notice like:

Parse error - syntax error, unexpected $end in /public_html/site1/wp-content/themes/my-theme/functions.php on line 278

To fix this issue you will have to correct the syntax. Most of the time it is a missing bracket, or some unexpected character in the code.

2. internal server error

WordPress  users may come across is “Internal Server Error”, or sometimes “500 Internal Server Error”. This error usually happens when there is something wrong, but the server is unable to idefntify where the problem is. Since the error message does not indicate where you should look for the error, it pretty much up to you to figure this out. We have compiled a list of solutions that you can try and one of them will help you resolve it.

3. Error Establishing a Database Connection in WordPress

This  error message is clear that your website is unable to connect to the database. However solving this error can be tricky for beginners. Usually this occurs when a user has entered or modified their database credentials.

4. WordPress white screen

This error usually results into a plain white screen with no error message which makes it the most puzzling because you have no clue where to look and what to fix. Most of the time it is caused when a script exhausts PHP memory limit.

5. WordPress Posts Returning 404 Error

The symptoms of this error is that when a user visits a single post on their site they get a 404 page – not found error. The user can browse all other sections of their site including the admin area. The most common cause of this issue is permalink settings in WordPress.

 

WordPress FAQ

WordPress FAQ

Q. What are the types of hooks in WordPress
a. There are two types of hooks 1) Action hooks 2) Filter hooks

Q. What is custom field in wordpress?
a. Custom field is a meta-data that allows you to store arbitrary information to the wordpress post.

Q. What is the prefix of wordpress tables by default ?
a. By default, wp_ is the prefix for wordpress.

Q. What is WordPress Loop
a. To display post WordPress use PHP code, this code is known as loop.

Q. Why widget does not show up in the sidebar?
a. While using widget you have to ensure whether your theme supports the widget and if it does then it must show the sidebar. If in any case if it happens that you don’t see the sidebar then it might be missing the “function.php” file or file similar to that. This can also happen if you have forgot to save the changes in the widget or refreshing the older display of the page.

Q. What are meta-tags?
a. Meta-tags are keywords and description used to display website or page information.

Q. What are the reasons why one should not hack WordPress core file?
a. The best reason not to hack the core files is that whatever you might be doing has to be reworked as a patch.

Q. How to hide the top admin bar at the frontend in WordPress?
a. Add below line in function.php
add_filter('show_admin_bar', '__return_false');

Q. How to hide Directory Browsing in WordPress from server?
a. Add following code in htaccess file
Options -Indexes

Q. How to display custom field in wordpress?
a. echo get_post_meta($post->ID, 'keyName', true);

Create change password Page

Create change password Page

to create a change password page for user in WordPress

just save the code into your current theme directory

Create new page in wp-admin/page name it as change

select template “change password”

publish it. thats all its done .

 

code 

 

 

Change WordPress default email

Change WordPress default email

Every time someone submitted a comment on your blog, signed up as a user or did anything that required WordPress to generate and send an e-mail, by default the “From Name” in that message appeared as “WordPress” and “From” address was “wordpress@your-domain.com”.
if you want to change this, just copy the below code to your functions.php

 

WordPress post formats

WordPress post formats

WordPress allows you to switch on different post formats from a set list. You don’t have to use all of them, you simply have to pick which formats suit your site best. At the moment, this list consists of:

  • Aside: Similar to a quick note. Use these for posts like quick updates or custom status’.
  • Gallery: A post containing a gallery of images.
  • Image: A single image, rather than a gallery.
  • Video: A post that has one, or several, videos. The WordPress codex also points out that a single URL may indicate the source of a video, rather than an embedded video.
  • Audio: An audio file or playlist.
  • Link: A simple link to an external site.
  • Quote: A quoted block of text, usually with attribution to a quote’s author.
  • Status: Similar to aside, but much more about a simple one-line status.
  • Chat: A full chat transcript.

In your Functions.php add this code