Solved

add alt tag and width/height

Posted on 2010-11-11
1
374 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
ID: 34117017
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to dynamically set the form action using jQuery.

920 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

19 Experts available now in Live!

Get 1:1 Help Now