Enabling Image Formatting In Your Wordpress Template

20th November 2008 - 2 minutes read time

One neat thing about Wordpress is the ability to add images to your posts in a quick and easy manner. You can also create thumbnails of larger images and link to them using a captioned image. The only problem is that when you have sorted out how your images look in your post in the admin section they just don't appear the same in your template once you have published it.

This is because Wordpress creates a set of styles that are used in the admin section and the default Wordpress templates. However, these styles are usually left out of custom template stylesheets. If you want to use the same sort of formatting that the Wordpress admin section has then open up your stylesheet file in your template and put the following stylesheet rules in at the bottom.

  1. .alignleft {
  2. float:left;
  3. margin:20px 20px 20px 0pt;
  4. }
  6. .alignright {
  7. float:right;
  8. margin:20px 0pt 20px 20px;
  9. }
  11. .aligncenter {
  12. display:block;
  13. margin-left:auto;
  14. margin-right:auto;
  15. }
  17. .wp-caption {
  18. -moz-border-radius-bottomleft:3px;
  19. -moz-border-radius-bottomright:3px;
  20. -moz-border-radius-topleft:3px;
  21. -moz-border-radius-topright:3px;
  22. background-color:#F3F3F3;
  23. border:1px solid #DDDDDD;
  24. margin:10px;
  25. padding-top:4px;
  26. text-align:center;
  27. color:#000000;
  28. }
  30. .wp-caption img {
  31. border:0pt none;
  32. margin:0pt;
  33. padding:0pt;
  34. }
  36. .wp-caption p.wp-caption-text {
  37. font-size:11px;
  38. line-height:17px;
  39. margin:0pt;
  40. padding:0pt 4px 5px;
  41. }

With this simple fix you will now have much better looking image styles.

One note for blog writers out there is that if you want to float an image left or right then you need to place it before the text you need to wrap it around. When you align things to the center the text will not wrap around it.

Add new comment

The content of this field is kept private and will not be shown publicly.