WordPress.org

Ready to get started?Download WordPress

Forums

Video Thumbnails
[resolved] Alt text on featured images (5 posts)

  1. da5idk
    Member
    Posted 1 year ago #

    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/

  2. Sutherland Boswell
    Member
    Plugin Author

    Posted 1 year ago #

    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() ) . '"

  3. da5idk
    Member
    Posted 1 year ago #

    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

  4. Sutherland Boswell
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  5. da5idk
    Member
    Posted 1 year ago #

    Perfect ! Many thanks :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags