Using php code to generate ALT for image ? Possible?

I would like to know if it is possible to use php code to generate an image ALT. In every page will be the same picture, but ALT will be different (that is the name of the page).

Exemple:

<img src="path-to-my-static-image" width="379" height="70" alt="<?php [B]some-code-here-to-import-wordpress-post-name[/B] ?>" />

Is possible to generate automatic ALT (post name) for the same image ? For wordpress ?

If you have a single image that carries several ALT, how search engines will index the file?
Once? Several times (the number of ALT)?

The alt text is what gets used for those people who can’t see the image. Unless the image is being used for a different purpose in each page it ought to have the same alt text as that is what people who can’t see the image will see or hear instead.

The only time that an image should have different alt text on different pages is where the purpose of the image is different. For example if you have a photo of you and your dog and one page is about you then the alt text might say ‘me with my dog’ while the same picture on the page about your dog might simply say ‘my dog Fido’.

Whatever alt text you use should convey the same meaning as the image would.

I cannot conceive of a situation where the same image would identify which page you are on for more than one page. If the image is supposed to identify the page then a different image would be needed for each page.

The only time that an image should have different alt text on different pages is where the purpose of the image is different

My intention was an improvement of SEO.

And economy of resources and labor.
I put the picture once and ALT change from one page to another.

There may be a code like the one that I mentioned above?

Try this:



<img src="path-to-my-static-image" width="379" height="70" alt="<?php echo $_SERVER['SERVER_NAME'];?>" />


 And replace SERVER_NAME with a parameter from the following list:

<pre>
 <?php print r( $_SERVER ); ?> 
</pre>


The alternative text has nothing to do with SEO. The intention of that attribute is to tell those people who can’t see the image why the image is included in the page. The text MUST relate to that reason or it will be meaningless and blind people and those with images turned off will be uable to use your page properly.

Try reworking the text that everyone can see if you need to update the page for SEO purposes.

The alt has a dual function. As said, it tells the blind what the image is, and it tells google (aka seo) what the image is. Word

<?php echo get_query_var('name'); ?>

this may work if you are using wordpress with seo friendly url

Oh, God. PicnicTutorials and kalpitz
You are brilliant. Absolutely brilliant.

You helped me a lot and I implemented in 2 minutes on my site code.

The code for wordpress is :

<a href=“<?php bloginfo(‘url’); ?>”>

<img

src=“path-to-my-image”
alt=“<?php echo the_title(); ?>”
title=“<?php echo the_title(); ?>”

>

</a>

Work like a charm. THANK YOU BOTH !!!

We romanian people think the same :stuck_out_tongue: I was wondering how to do this and was looking for this stuff for wordpress! Saw it on a website and loved the effects on the SEO, great job Alina :slight_smile:

Yes but the Google search engine bot effectively is a blind person as it can’t see the image. Of course for every bot that can’t see the image there are THOUSANDS of living people who can’t and the bots are trying to treat the page the same as those people do so targetting the real people is the best thing you can do for SEO.