How To: Wrap the post title around an image
How To: Wrap the post title around an image

How To: Wrap the post title around an image

by Alex · 18 comments

A great way to enhance the style of your images in your post is to have the title of your post wrap around your image. If you don’t under­stand what that means, then take a look at this post, and just about any other post on Blo­gus­sion. I got an email request on how to achieve this effect from our new friend Evan, so I decided that I would just write a post about how to do this.

To achieve this effect, you have to dive into your theme files and do a tiny amount of PHP/HTML/CSS cod­ing. It’s not hard at all, and there is very lit­tle cod­ing behind this method. I am sure there are other meth­ods (if not, a plu­gin) to do this, but this is the way we have grown accus­tomed to on Blogussion.

Before we start, I just want to run through a check­list of things you need to keep in mind through­out this short lit­tle “how-to”:

  • You use Word­Press as your blog­ging platform.
  • A basic under­stand­ing of Cus­tom Fields
  • You can edit a theme file

Step 1

Set­ting up your cus­tom fields

The way I do this is through cus­tom fields. Using cus­tom fields is a great solu­tion to this, because you can set up your image within your post screen with­out edit­ing any files.

If you need help set­ting up cus­tom fields, read below. If not, skip to Step 2.

In your post screen, right under your post box is another box called “Cus­tom Fields”. Very self explana­tory here: this is where you set up your cus­tom fields.

Inside the cus­tom fields box is an option to cre­ate a name for it. Click “Enter New” and enter the name of your cus­tom field. Remem­ber the name, because you will be using it every time you want your title to wrap around an image.
cfields

After you add the Name, click “Add Cus­tom Field”.

Step 2

Adding the code

This is the part where we will be edit­ing the theme files. You will need an FTP pro­gram (like Trans­mit or FileZilla) and a text edi­tor to edit the code (but work­ing inside of Word­Press will work just fine).

Go to your themes folder, open up ‘index.php’

Look for the piece of code (usu­ally) directly under The Loop that looks like this:

<div class=“post” id=“post-<?php the_ID(); ?>”>

Directly under that line, add this piece of code:

<div class=“excerpt”>
<?php echo get_post_meta(get_the_ID(), ‘CUSTOM_FIELD_NAME’, true); ?>
</div>

Replace the part ‘CUSTOM_FIELD_NAME’ with the name of the cus­tom field you cre­ated in Step 1.

Make sure you repeat this process in the single.php file too. That way, the image will show when some­one clicks on the title of the post.

Open up your Stylesheet (style.css)

We need to add a very short line of CSS so we can posi­tion the image in the right spot for the text to be able to wrap around it.

Paste this code any­where in your stylesheet:

.excerpt {
float: right;
mar­gin: 0 0 0 2.5em; /* spac­ing between image and text */
}

You may need to adjust the mar­gin depend­ing on your style sheet.

Don’t under­stand the mar­gin? You can edit the mar­gin from all dif­fer­ent sides in just this one line. It goes in order from left to right: top, right, bot­tom, left. If it helps you remem­ber, think of mar­gin as “T.R.B.L” — trou­ble ;)

Step 3

Putting the code to use

Now that all of the code is set up, you can now use your cus­tom fields to make the image of your choice show up.

How to make your image appear

Once you go back to the post screen and write up your post, go back to the Cus­tom Fields screen. Click on the drop down menu and look for the cus­tom field you cre­ated ear­lier and used as the name in your code. Always remem­ber to use this cus­tom field for all of your images, or you may find that some of your images may not show up or disappear.

Now that you have selected the name, edit the box right next to it called Value. You need to enter the image code into this sec­tion. You can use this image code below:

<img src=“URL OF IMAGE HERE” alt=“ALT TEXT HERE” title=“TITLE TEXT HERE” />

Use that every time you want to use the image. If you don’t want your title to wrap around an image, then don’t. This code will not have any effect on posts that do not use this method to show its image.

I hope you have learned some­thing. If you have any ques­tions, or can improve this code then let me know!

Go to top

Article by Alex

I'm the 17 year old blogger & designer behind Blogussion. I live in New Jersey (but root for the New England Patriots), and am a Junior in High School. You can check out my rarely updated personal(ish) blog, Asnio, or connect with me on Twitter.

From Planning to Earning

A free course that explains all you need to know about maintaining and building a powerful, money making blog.

Information is delivered through a beautiful web guide & a 10 day email course (+ a weekly newsletter). Sign up, or learn more!

Corey Freeman February 21, 2009 at 7:56 pm

It would be significantly easier, i think, to hard code the image code and just paste a URL into the value field. You lose the alt text attribute, but it’s not as annoying to create feature images.

Reply

Alex February 21, 2009 at 8:01 pm

That’s how we have it here, but for the sake of neatness in the tutorial I just decided I would add that tag in the custom field. The only thing I have against that (but I still do it) is that when you don’t have an image with text wrapping, then it will have a blank tag in the source code. It’s not a huge issue, but like I said “neatness”.’ ;)

Reply

Janith February 21, 2009 at 8:08 pm

I didn’t even know we used this method :P
In fact, I don’t know how you managed to set it up – but all I know is ~ it looks good and I can manipulate it :)

Kudos to Alex on setting the Blogussion Theme up, it’s just perfect :)

Reply

Janith February 21, 2009 at 8:06 pm

The ALT Text Attribute is significant when it comes to SEO, because crawlers can’t obviously work out pictures and they play a major role when it comes to identification.

Also, there are many users that use devices to read out loud what is displayed on the site, and a missing ALT attribute fails here as well.

Coming back to a SEO point of view, every image without an ALT tag is a ‘minus’, especially if you have a image-based website or a lot of eye-candy imagery – your site can take a heavy hit on the SERPs.

Reply

Evan February 21, 2009 at 10:39 pm

Thank you for posting this! It answered my question very thoroughly and it it will be very helpful to me and my blog. Once again, thanks! :)

Evan’s last blog post..It’s A Sweet Thing

Reply

Alex February 21, 2009 at 10:42 pm

No problem man. If you need any help, don’t hesitate to ask. :)

Reply

Stuart Conover February 21, 2009 at 10:50 pm

Appreciate the quick guide on how to set this up. I’ve been debating how I want to setup one of my future blogs and this has given me another idea from which route to pick. Of course, having one more option perhaps I should be annoyed that it shall be that harder to choose how I want to style it ;)

Stuart Conover’s last blog post..Review: eCommerce Action Pack by: Jon Lewis

Reply

Alex February 21, 2009 at 11:28 pm

Just keep experimenting. You’ll find something you like. :)

Reply

John Ankarström May 24, 2009 at 8:58 am

How can I do this with Thesis WordPress Theme? You can send an email to me if you respond (forgot to check the notifier checkbox). Thanks.

Reply

Alex May 24, 2009 at 10:46 am

It’s automatically done, go to Thesis Options then Post Images and Thumbnails, you can change how the image shows up.

Reply

John Ankarström May 25, 2009 at 2:14 pm

Oh, thank you! I recently got the Thesis Theme, and I’ve never used the post images and thumbnails before.

John Ankarström’s last blog post..Execute PHP code in posts with WordPress Plugin

Reply

Nick Tart May 25, 2009 at 1:42 am

Do you design/create all of the Post Images for your articles?

Nick Tart’s last blog post..‘Marketing’ Has More P’s Than ‘Hippopotamus’

Reply

Alex May 25, 2009 at 10:54 am

Most of them, but I also use Flickr a lot to find images too.

Reply

Play online casino craps June 11, 2009 at 4:29 am

Awesome stuff. Came to your blog from my friend’s site and wasn’t expecting to find something actually useful. was expecting to just find something random and comment for the do follow love :p being honest :) .I wanted to use something like this in my about page but landed up putting the image below. didn’t realise you could just float it. been using float=”right” but seems like there are a few ways to initialise these things (come from java background so weird that you can use so many methods)

Reply

Mark May 10, 2010 at 9:46 am

You may have not intended to do so, but I about you obtain managed to indicate the state of haul that a oceans of people are in. The common sense of inadequate to escape, but not crafty how or where, is something a straws of us are contemporary through.

Reply

Double Bass Strings May 27, 2010 at 4:12 am

Superb study, I just passed this onto a colleague who was doing just a little study on that. And he really bought me lunch simply because I found it for him smile So allow me rephrase that: Thanks for lunch!

Reply

Leave a Comment

CommentLuv Enabled

2 trackbacks