WordPress.org

Support

Support » Plugins and Hacks » Video Thumbnails » [Resolved] Alt text on featured images

[Resolved] Alt text on featured images

  • Hi – thanks for a great plug-in. I am using it on a redevelop for a client’s website, so they can put videos on their site.
    Can you take a look at the following for me:

    ————————————–
    <?php query_posts('category_name=news&showposts=6'); ?>

    <?php while (have_posts()) : the_post(); ?>

    <div class="newsbox">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php if(get_video_thumbnail()!=null) { echo‘<imgsrc="'.get_video_thumbnail().'" alt="<?php the_title(); ?>" class="video-thumbnail">'; } elseif(has_post_thumbnail()) {the_post_thumbnail(); }; ?>`
    <?php if(get_video_thumbnail()!=null) echo '<img src="/img/play-button.png” alt=”play video” width=”40px” class=”overlay”>’; ?>`
    <a href="<?php the_permalink(); ?>"
    title="<?php the_title(); ?>"><h3><?php the_title(); ?></h3></a>
    <?php the_excerpt(); ?>
    </div>

    <?php endwhile;?>

    <?php rewind_posts(); ?>
    ————————————–
    [I’m finding it very difficult to post code on here!]
    ————————————–

    The
    alt="<?php the_title(); ?>"
    just reproduces itself in the source, without actually pulling the title for the alt.
    I would welcome your help with it.
    regards
    David

    http://wordpress.org/plugins/video-thumbnails/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Sutherland Boswell

    @sutherlandboswell

    Try posting large blocks of code to Pastebin, but from what I can tell the problem is that you’re already echoing a string, so instead of wrapping the_title(); in <?php ?> you need to do the same thing you did for the src attribute, so it should look like alt="'.the_title().'"

    Also, wrap it in addslashes() so that if a title has quotation marks it won’t break the quotes wrapping the alt attribute. alt="' . addslashes( the_title() ) . '"

    Aha – many thanks for getting back to me. The code is now at http://pastebin.com/FMGt8bH9#

    Unfortunately the suggestion you made above delivers the title outside of the code, and an empty alt, so i get

    <a title="... the title...." href="http://blah...blah...">
    ...the title....
    <img class="video-thumbnail" alt="" src="http://blah..blah....

    meaning that the title then appears as text on the page, rather than hidden as an alt in the code…not sure why that would be!

    David

    Plugin Author Sutherland Boswell

    @sutherlandboswell

    Oops! Should be alt="' . addslashes( get_the_title() ) . '" because without get_ it will try to echo the title instead of just insert it into what is already being echoed.

    Perfect ! Many thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Alt text on featured images’ is closed to new replies.
Skip to toolbar