2

I have the following

 <?php echo '<img src="/wp-content/themes/CAFC/images/cards/big/'.get_post_meta($post->ID, "bigcard", true).'" alt="'.the_title().'" />'; ?>

For some reason however my 'the_title' variable is appearing before my image when outputted as so...

UK Fuels Fuel Card
<img alt="" src="/wp-content/themes/CAFC/images/cards/big/ukfuels.png">

Can anybody give me an idea of where im going wrong?

3
  • are output buffers active? php.net/ob_start Commented Apr 19, 2012 at 17:33
  • Oops. Deleted my comment. Anyway, try using the standard "View source" rather than Firebug. Should show up correctly. Commented Apr 19, 2012 at 17:34
  • Also, I misunderstood your problem. Thought you were asking why "alt" was before "src". Commented Apr 19, 2012 at 17:35

4 Answers 4

5

This is because the_title() auto echoes the title. Try get_the_title() instead.

Sign up to request clarification or add additional context in comments.

1 Comment

If it's WordPress, you can pretty much assume it will auto echo. This is to make things "easy" I suppose. #dumb
1

Try to use as:

$title = the_title();

and, use this $title in place of the_title();

Comments

0

Use this instead:

<?php echo '<img src="/wp-content/themes/CAFC/images/cards/big/'.get_post_meta($post->ID, "bigcard", true).'" alt="'.get_the_title().'" />'; ?>

Comments

0

I think it's your browser. It changes the position of attributes for you. F. ex. Firefox can fix some HTML code according to standard.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.