Can’t Align Images in WordPress? Fix it

Ads

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.

  • http://q.apher.com/ NetPuter

    Thx very much.
    I need it!

  • http://blogote.com Rockstar Sid

    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!

  • http://www.pakspider.com Muhammad Asad

    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 ??

  • http://www.wondersnet.com Wonder Wyant

    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.

  • derek

    Wow! You are a savior! Thought I was losing my head.

  • http://www.teensfashionnews.com Usman

    thx very much. you solve my big problem.

  • Richard

    That fixed it. Thank you very much!!!

  • Richard

    That fixed it. Thank you very much!!!

  • dvac

    you. are. a. life. saver. i was messing with that for 30 minutes not knowing what i was doing wrong. i gave up and googled. first suggestion. well done.

  • Levi-d

    Thanks a lot mate, it works brilliant :)

  • 34sd

    Thank you!!

  • http://www.facebook.com/AymanAmer87 Ayman Amer

    where to add this code exactly in the stylesheet file?