WordPress.org

Ready to get started?Download WordPress

Forums

How to remove post image as attachment wordpress? (6 posts)

  1. wzshop
    Member
    Posted 1 year ago #

    Hello,
    I was wondering if it is possible to add an image to a post, by adding it as media, but not let it show up as an attachment in that post.

    Any possibility for this?
    Thanks.

  2. riversatile
    Member
    Posted 1 year ago #

    Hi,

    Some themes manage post thumbnail automaticaly when you upload images to a post.
    Is this the case ?
    Do you click on "Use as thumbnail" link ?

    What is your blog URL ?
    What is the theme name ?
    Try to find an option somewhere you can disabled this features (theme option).

  3. wzshop
    Member
    Posted 1 year ago #

    Hi riversatile,
    Thanks a lot for your reply! Im not sure what you mean. Here is what i did; created a new post and clicked on the 'add media' icon. I uploaded a file an inserted it into the post. Then i saved the post. Now i use the WP User Frontend plugin which shows the $attach (the attachment) at the bottom of each post. I do want to keep that option, so that people can upload an attachment when they want to. Nevertheless since it saves the uploaded image as an attachment too, it displays the same image twice per post.

    Anyway to avoid that? Hope i made myself more clear.
    Thanks a lot!

  4. riversatile
    Member
    Posted 1 year ago #

    OK... It's more difficult now !

    I think this comes from your theme.
    Do like me, you can analyse with Google Chrome inspector how the attachment block is builded.
    Then you will know what to change in which file of your theme.

  5. wzshop
    Member
    Posted 1 year ago #

    Hi,
    Thanks again for your reply.
    You're suggesting that the template causes for the image to be saved as attachment to the post? Guess this should be a general wp setting right? And since the WPUF plugin echo's the attachment, the image gets shown twice.

    Anyone?
    Thanks.

  6. wzshop
    Member
    Posted 1 year ago #

    Ok fixed it. Not a beauty i guess but it works. For anyone who has this problem go to the wpuf-functions.php file and search for line 563. Here are some changes needed.

    //if the attachment is image, show the image. else show the link
                    if ( wpuf_is_file_image( $file['url'], $file['mime'] ) ) {
                        $thumb = wp_get_attachment_image_src( $file['id'] );
                        $attach .= sprintf( '<li><a href="%s"><img src="%s" alt="%s" /></a></li>', $file['url'], $thumb[0], esc_attr( $file['title'] ) );
                    } else {
                        $attach .= sprintf( '<li><a href="%s" title="%s">%s</a></li>', $file['url'], esc_attr( $file['title'] ), $file['title'] );
                    }
                }

    Replace it with:

    //if the attachment is image, show the image. else show the link
                 				$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    							$wpuimage = wpuf_is_file_image( $file['url'], '');
    							if ( $wpuimage !== $feat_image) {
    				if ( wpuf_is_file_image( $file['url'], $file['mime'] ) ) {
                        $thumb = wp_get_attachment_image_src( $file['id'] );
                        $attach .= sprintf( '<li><a href="%s"><img src="%s" alt="%s" /></a></li>', $file['url'], $thumb[0], esc_attr( $file['title'] ) );
    
    				} else {
                        $attach .= sprintf( '<li><a href="%s" title="%s">%s</a></li>', $file['url'], esc_attr( $file['title'] ), $file['title'] );
    				}
                    }
                }

    This looks if the url of the post thumbnail is the same as the attachment image url and if so, not attachment is shown.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic