Tips and Tricks

WordPress Center Images – 1 line solution without plugin

While working with WordPress post editor in Admin Panel, you may have noticed that even after you have selected an image and clicked on “Align Center” button, the image does not appear centered when the post is viewed i.e. the WordPress Center Images function does not worry correctly on front end.   The image shows up as centered in the editor, though.  In this post, I am going to give you a 1 line solution to solve this problem and center images in WordPress, all without using any plugin.

How to Center Images in WordPress

Let me illustrate the exact problem by means of the following image:

WordPress Center Images Problem

Solution:

In your theme that you are using for the WordPress, add the following style in the style.css style-sheet:

WordPress Center Images: Solution

Alternately, you may copy the following code directly into the style-sheet:

.aligncenter, img.aligncenter {
margin-left: auto; margin-right: auto; display: block; clear: both;
}

WordPress Center Images: Problem Solved!

As you can see, the images are now aligned perfectly to the center.

Hope this solution helps out the needy.

Your Turn!

If you have any questions, please leave a comment below.

Share your thoughts, comment below now!

*

*