WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove Img Title (3 posts)

  1. noelgreen
    Member
    Posted 4 years ago #

    I have the following code to grab the thumbnail images from the posts.

    <?php
    $attachments = get_children("post_parent={$post->ID}&post_type=attachment&post_mime_type=image&numberposts=1");
    foreach ( $attachments as $att_id => $attachment) {
    echo wp_get_attachment_image($att_id, 'thumbnail');
    }
    ?>

    That works great. But I need to remove / not display / hide the "Title" of the image. So that when someone does a mouse over on the image it won't display the "title" as a pop-up.

    Any ideas?

  2. noelgreen
    Member
    Posted 4 years ago #

    Figured it out.
    Based on this post I changed my code to this.

    <?php
    $featured_image = array();
    $args = array(
    	'post_type' => 'attachment',
    	'numberposts' => 1,
    	'post_status' => null,
    	'orderby' => ID,
    	'post_parent' => $post->ID
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    		$featured_image = wp_get_attachment_image_src($attachment->ID, $size='thumbnail', $icon = false);
    	}
    }
    echo '<img src="' . $featured_image[0] . '" alt=""/>';
    ?>
  3. CrunchyToast420
    Member
    Posted 4 years ago #

    Also, in 2.9.2 you can open up media.php and comment out line 565.

    //'title' => trim(strip_tags( $attachment->post_title ))

Topic Closed

This topic has been closed to new replies.

About this Topic