Can’t Align Images in Wordpress? Fix it

Wordpress 2.5+ introduced a new image gallery system and correspondingly a new way to align images which was relatively intricate compared to the old one.

The main problem I faced using the new system until now was that I couldn't make Wordpress align the images properly for me. I thought I was the only one facing this problem but a helpful post by Daniel made it clear that there are perhaps more users facing the same problem.

I am sharing the fix just in case someone comes searching through to find a fix for this problem. All you need to do is add the following piece of CSS code to your theme stylesheet and you are good to go.

img.centered {
display: block;
margin-left: auto;
margin-right: auto;
}

img.alignright {
padding: 4px;
margin: 0 0 2px 7px;
display: inline;
}

img.alignleft {
padding: 4px;
margin: 0 7px 2px 0;
display: inline;
}

.alignright {
float: right;
}

.alignleft {
float: left;
}

This will make Wordpress aware of all alignments.

  • Thx very much.
    I need it!
  • Rockstarsid
    Thanks :D I changed from Wordpress editor to WLW because of Image alignment problem..

    Testing this code.. :)
  • Xtd
    Thanks, worked wonders!
    My wife was almost about to give up on our family blog so this saved my day!
  • I was looking for the same fix. Thanks!
  • Glenn Kilpatrick
    Hi guys. I checked my css and this is present. The problem I have is slightly different. I cant stop the text from wrapping around an image.

    Any help please ??
  • Thanks so much for this. I should have "gotten it" on my own but . . . you saved me from tearing out my gray hair.
  • Janne Toft Jensen
    Thank you so much! Fixed one of two remaining problems on my blog :-)

    You wouldn't happen to know how to make the page navigation work (appear) in the Cutline theme when using the 2.6.3 version of Wordpress - would you...?
  • Tsotlah
    You are a lifesaver! Thought I was doing something wrong.... Thanks for the help
  • Kiley
    Thank you so much for this! I was beating my head against the wall trying figure out why my images weren't aligning.
  • Richard
    That fixed it. Thank you very much!!!
blog comments powered by Disqus