Image url changed for same image source in wordpress - wordpress

I used an image in portfolio page as well as in slider.
In the portfolio page the image is rendering correctly with the url /wp-content/uploads/2015/08/em-hospital-2.png?resize=300%2C223 300w, /wp-content/uploads/2015/08/em-hospital-2.png?w=498 498w .
In the slider, the image url (/wp-content/uploads/2015/08/em-hospital-2.png?fit=1%2C1) get changed and is not rendering.
I am not able to understand why fit=1%2C1 added at the end.

if you use featured image in slider and on portfilo page than can you please try this
<?php
$thumb_id = 25;
$url = wp_get_attachment_thumb_url( $thumb_id );
?>
<img src="<?php echo $url ?>"/>
Here $thumb_id = 25; Is Post ID you can replace 25 with your post ID

Related

Wordpress blog page featured image

I like to use the page's featured images in a background image in the header. When I add a new page and set the featured image, it appears as background image works exactly what I wanted. But on a Blog main page (the Home, page of displaying posts) I set the featured image and in the header display the first post's featured image insetad the one I set at the page's featured image. Tried to find solution, but nothing works, don't know how to magae it. Here is my code that handle background image:
<div class="sub-header"
<?php
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
echo 'style="background-image: url(\'';
echo $image[0];
echo '\');"';
endif;
?>
>
</div>
Make the custom image source, whether it's assigned in the customizer or hard coded.

How Can i set the Img Post Thumbnail as a background of whole post

anyone help me to make the full background of my wp loop posts is the thumbnail of featured image of the post
enter image description here
In your header.php OR single.php file (wherever your opening <body> element is) you can do something like:
<body style="background: url('<?php echo get_the_post_thumbnail_url($post->ID, 'thumbnail'); ?>') no-repeat center center;">
OR you could wrap your post in a new wrapper div and set the background the same way. Note You will have to be inside the loop to use the $post object properly OR you can call global $post; at the top of the file you are trying to set this on.
If you wish to use the full version of the uploaded featured image, simply change the thumbnail parameter to full in the get_the_post_thumbnail_url() function.
Reference: https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
You can get featured image url in wp loop by post id and add featured image as background image to your main div
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID, 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')"></div>

Featured video and image thumbnails from external links in Wordpress

Is there a way to get a thumbnail from any website link? For example, if I take a link from imgur and post it on my website in the post itself, it shows the image. But when I go to the homepage of my website there is no featured image for that post. Just a great box. How could I generate a featured image of any link I posted from an external website?
I have used the video thumbnail plugin but it only works with certain websites.
try going into page.php of your theme, then search for the_post_thmbnail(). There add the image link
change this line:
<?php the_post_thumbnail(); ?>
to something like this:
<?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
if( $name ) { ?>
<?php the_post_thumbnail(); ?>
<?php } else {
the_post_thumbnail();
} ?>
hope this helps :)

Wordpress not showing thumbnails

I am using the Plugin Auto Featured Image to set thumbnails automatically. And in the database it shows updated meta thumbnail key.
But for some reason it is not showing the featured image. It doesn't show a "placeholder" neither. It just shows nothing at all.
Also, when I try to view the attachment on a single page, it does not show it.
How can I proceed to find the problem? If you need more screenshots of different tables on my database, please ask. I really appreciate your time.
EDIT
$meta_values = get_post_meta( $POST_ID, '_thumbnail_id');
error_log(var_dump($meta_values)) //Prints nothing on error log
//Note: $POST_ID is fine, it contains the right id. Problem not there.
EDIT 2:
if ( has_post_thumbnail($post_parent_id) ){
error_log("THUMB EXISTS". get_post_thumbnail_id($post_parent_id));
}
Really weird result:
THUMB EXISTS: "Blank space, No id or string at all"....
1) get post thumbnail with post id full description
<?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
2) In a loop full description
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
3 want to get the thumb url ?? . Use this
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
<img src="<?php echo $url; ?>" longdesc="URL_2" alt="Text_2" />

Wordpress - Can't output image (from custom field) for previous and next posts

I am working on a portfolio website. Whenever a portfolio piece is clicked, the user is taken to a page that shows details about that piece (i.e. more photos and information). There will also be previous and next navigation links to get to additional pieces. However, I want the previous and next navigation links to be a thumbnail photo of the next piece (custom field for that is thumbnail_photo). This is what I have so far:
<?php
$previous_post = get_previous_post();
$next_post = get_next_post();
$prev_value = get_post_meta( $previous_post->ID, 'materials', $single = true);
$next_value = get_post_meta( $next_post->ID, 'thumbnail_photo', $single = true);
?>
<p><?php echo $prev_value; ?></p>
<p><?php echo $next_value; ?></p>
I used 'materials' in the call for $prev_value since 'materials' is another custom field. I just wanted to see if it was actually working. It outputs the materials just fine, but it only outputs the ID number of the thumbnail_photo. I can't get it to reference the file name so that I can output the actual image.
I am using the Advanced Custom Fields plugin, so each image is stored as an image object. So this is how I would typically output a thumbnail image:
<?php
$image = get_field('thumbnail_photo);
echo $image[sizes]["thumbnail"]; // thumbnail is a reference to wordpress' thumbnail media size
?>
When you configure the ACF input field, be sure you set the return value to be an image object instead of the image ID after change this, or if you already changed, you have to update the post or posts you're trying to get. Because, if you set the field return value as image ID, created the posts and now you wanna change their values you have to modify all the posts because every post_meta is containing the ID of the image.
In the ACF website has a tutorial how you could get the values an turn into images:
With the ID
<?php
wp_get_attachment_image( $next_value, 'thumbnail' );
?>
Another Example With the ID, but this time you have to create the image HTML, the function returns an array with the url, width and height
<?php
$image = wp_get_attachment_image_src( $next_value, 'thumbnail' );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<img src="<?php echo $image[0]; ?>" />
You could do a check for the returned value and then write the image, example:
<?php
if( is_int( $next_value ) ) {
wp_get_attachment_image( $next_value, 'thumbnail');
} elseif ( is_object( $next_value ) ) {
echo $next_value['sizes']['thumbnail'];
} else { ?>
<img src="<?php the_field('field_name'); ?>" alt="" />
<?php } ?>
I didn't test it, but I think it works fine.
I hope this help and sorry for the bad english

Resources