Solved

add alt tag and width/height

Posted on 2010-11-11
1
356 Views
Last Modified: 2012-05-10
I have the following bit of code, which will display an image from the custom fields in wordpress.

<?php $image = get_post_meta($post->ID, 'image', true); 
		              if ($image > "0") { echo eval("?><img src=\"".$image."\"/><?"); } ?>

Open in new window


What i want to be able to do also, is automatically add alt tags, and have a default height and size so that the admin can just insert the image filename and not worry about resizing or adding alt tags.

how would i add the following to the above code?

alt="<?php the_title(); ?>" height="220" width="230" />

Open in new window

0
Comment
Question by:jonathan1978
1 Comment
 
LVL 13

Accepted Solution

by:
AngryBinary earned 500 total points
Comment Utility
Give this a try:

<?php
    $image = get_post_meta($post->ID, 'image', true);
    if ($image > "0")
    {
    ?>
        <img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" height="220" width="230" />
    <?php
    }
?>
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now