SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up 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:

    Code:
    <img src="path-to-my-static-image" width="379" height="70" alt="<?php some-code-here-to-import-wordpress-post-name ?>" />
    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)?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,805
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Pamela Alina View Post
    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:

    PHP Code:

    <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>
    Last edited by John_Betong; Jun 13, 2013 at 17:23. Reason: formatting and spelling: not my fortay

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Pamela Alina View Post
    My intention was an improvement of SEO.
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    Code:
    <?php echo get_query_var('name'); ?>
    this may work if you are using wordpress with seo friendly url

  8. #8
    SitePoint Enthusiast Pamela Alina's Avatar
    Join Date
    Jun 2013
    Location
    Romania
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 !!!

  9. #9
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We romanian people think the same :P 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

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    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
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •