New answers tagged

0

You should be able to write a php script to do this for each post. You'll need to do a query to get all the posts, then loop through that setting the featured image to your desired image on each post. This question has specific code that should get you started.


1

There's a couple things that you need to do to get the URL - you could combine them into one long sentence probably but I'll break it down. WordPress stores the thumbnail ID in the postmeta table as _thumbnail_id so we need to get that using get_post_meta(): $thumb_id = get_post_meta( $post->ID, '_thumbnail_id', true ); Now that we have the ID we need ...


2

You are correct, you will need to get the image URL and set is as a variable so you can echo it out as an inline style in your HTML. I've updated your foreach loop below and set the image as an inline style of your <li> element: foreach( $postQuery as $post ) : setup_postdata($post); if ( has_post_thumbnail() ) { ?> /* Get the post ...


0

Alternative solution here: http://pixert.com/blog/cropping-post-featured-thumbnails-from-top-instead-of-center-in-wordpress-with-native-cropping-tool/ Just add this code to functions.php, then use "Regenerate Thumbnails" plugin (https://wordpress.org/plugins/regenerate-thumbnails/): function px_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, ...


0

Here's the relevant part of your code that should work: // This will make a URL like http://yoursite.com/path/to/fallback.png $fallback_image = site_url( '/path/to/fallback.png' ); $fallback_image = "<img src='{$fallback_image}' />"; foreach( $recent_posts as $recent ){ echo '<div class="sidebar-entries">'; $featured_image = ...


-1

The default image sizes of WordPress are “thumbnail”, “medium”, “large” and “full” (the size of the image you uploaded). These image sizes can be configured in the WordPress Administration Media panel under Settings > Media. This is how you can use these default sizes with the_post_thumbnail(): the_post_thumbnail(); // without parameter ...


3

I have updated your code so that the fallback image has post permalink. I hope this helps: if ( has_post_thumbnail() ) { echo '<a href="' . get_permalink($post->ID) . '" >'; the_post_thumbnail(); echo '</a>'; } else { echo '<a href="' . get_permalink($post->ID) . '" ><img src="'. get_stylesheet_directory_uri() . ...


1

The problem is when you are trying to get the template directory. You are getting it instead of printing bloginfo() prints the output get_bloginfo() retrieves the output So, the nice piece of code should look like this: <?php if ( has_post_thumbnail() ) { echo '<a href="' . get_permalink($post->ID) . '" >'; the_post_thumbnail(); ...


0

With this code in header.php and some tweaks I fix it and I disable social yoast and activating another plugin open graph which let me choose what tags I want. <?php global $post; $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post -> ID ) , 'thumbnail' ); if(strlen($src[0])){ echo '<meta ...


0

The way around this is pretty simple, however. You can just install a plugin that automatically sets the featured image from the first image in a post. Of course that means you will need to make the animated image the first image, but at least it’s a workaround. There are a number of plugins that will let you automatically set your first image as the ...


0

If you need to control the image that is used when shared to facebook, might I suggest doing the following within Yoast SEO: Once the plugin is installed, you will have a Yoast SEO settings panel below your post and page editor. On this panel there is a social tab. Within this tab you are given the ability to edit the image used when users share via ...


1

It's because those GIF images exceeds the max-size supported by Facebook open graph ( 8Mb ). Check the debugger for Open Graph here For instance for post vbnvnvb , debugger show this error


2

I think the problem may be that the_post_thumbnail() doesn't accept an ID as a parameter. Instead you should use get_the_post_thumbnail() which does accept an ID as a parameter: <?php echo get_the_post_thumbnail($authors_post->ID); ?>


1

You'll have to code the output in the manner you want to display it. However you'll have to generate the image link prior to the html part. Save the image in a variable $bgimage1; make the list using li and in the list item backgroun-image: <?php echo $bgimage1; ?>


0

try this way $image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'large', false); <img src="<?php echo esc_url($image[0]);?>" alt="">


4

WordPress uses min( intval($content_width), $max_width ) inside image_constrain_size_for_editor for large image size. As I can see your $content_width is set to 660. So, change the $content_width in your functions.php file to the 1024 or whatever you need. For full-width layout, it's better to remove it. Example: $GLOBALS['content_width'] = 1600. That's ...


0

You're doing right. Just miss one step. I guess you upload image before change the size of large in setting. Final step is Regenerated thumbnail. Just install the plugin with same name, go to Tool > Regenerate thumbnail and click. ;)


0

the_post_thumbnail() can only be used in "the Loop". What you need is get_the_post_thumbnail(). (See details and code examples on the code reference page). So something like: foreach( $recent_posts as $recent ){ echo '<li>'; echo get_the_post_thumbnail( $recent['ID'], 'size', array( 'class' => 'alignleft' ) ); echo '<a href="' . ...


0

I think you might be jumping the gun with actively discarding the data here. What if next month trolls go away, you change your mind, and want all those featured images back? I would just suppress them on front end by editing template and making thumbnail output conditional or filtering API with something like this: if ( ! is_admin() ) { add_filter( ...


0

@Romulus Since you are using Wordpress, I would highly suggest using Wordpress' functionality as much as you can. I would recommend using PHP and creating your own plugin or some kind of script that you can run. There are lots of tutorials out there that will give you the bare-bones implementation for creating a simple WordPress plugin. For now I'll run ...


0

I think this code will help you: $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false, '' ); echo '<img src="'.$src[0].'">';


0

That message is a general PHP error saying that you are trying to use a variable like a PHP object when it is not a PHP object. If you read the docs for get_previous_post() and get_next_post(), you can see that those functions return a post object or null/empty string if the previous/next post couldn't be determined. So, you need to check that you have an ...


0

Finally sorted it out. As I am using Advanced Custom Fields, I need to use the acf/save_post hook with a priority greater than 10, so the get_field() functions are available. Downside is that this hook runs for every post type. As opposed to the WP native save_post hook, with the ACF one you can't hook it for a specific custom post type. So I also added a ...


0

@Ibraheem, you don't have to use global $post, since it is in global. To check post type you can use get_post_type(). Using the_post_thumbnail is not properly implemented in this case, instead use get_the_post_thumbnail. Note: you can't use has_post_thumbnail as tag condition if you are not set featured image. add_filter( 'the_content', ...


2

Yes, this is trivial in WordPress. Whenever you upload image WP keeps original file and generates additional sizes from it. Several of the sizes are built–in (see Settings > Media > Image sizes) and any additional ones can be added with add_image_size(). So when you develop your own theme as part of the process you: Determine image size you need. ...



Top 50 recent answers are included