WordPress not centring images when you tell it to? Here's how to fix that

29 August 2018

So you've got yourself a shiny new self-hosted WordPress blog. You create a post or page, insert an image, and decide to centre it (or 'center' it if you're not a Brit like me!) using the "align centre" button in the post editor. The image looks centered in the editor... but when you publish the post, it's still left aligned. What gives?

Align Centre

The 'Align centre' button within WordPress's so-called 'Kitchen Sink'

When you centre an image in WordPress like this, it is given a CSS class of "aligncenter". However it's up to your theme, or more specifically your theme's stylesheet, to say what that class actually does. If your WordPress site is not playing ball, it may be that your theme is missing the bit of code that does that.

The good news is, it's easily fixed. You will need to add the snippet below to your theme's CSS:

Your particular theme may have an option to add CSS without delving into the stylesheet itself - and if it does, use that. However, if it doesn't, follow the below steps:

  1. In the WordPress menu, go to Appearance > Editor
  2. Select your theme (or ideally, your child theme) in the drop-down menu in the top right
  3. Make sure 'Stylesheet' (style.css) is selected under 'Theme Files' on the right
  4. The main content area will show your stylesheet. Paste the snippet at the bottom of this
  5. Click the blue 'Update File' button

Et voila! You may have to hard refresh your browser (press the Ctr and F5 keys together) before you see the change take effect.

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © James Clark
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram