Thumbnails regenerate wp_generate_attachment_metadata
Thumbnails regenerate wp_generate_attachment_metadata
Thumbnails regenerate wp_generate_attachment_metadata
What you’re apparently asking for isn’t possible. WordPress will never add white space to an image to make it fit a certain size. This is what cropping means. Cropping will always remove (i.e. crop) some of the image so that it fits a certain size. As far as I am aware, there is no tool … Read more
I’ve reached the “problem” My theme had no “thumbnail” suport. I just add the line add_theme_support( ‘post-thumbnails’ ); on funcions.php Veja detalhes em https://codex.wordpress.org/Post_Thumbnails
Please try the code given below: function auto_featured_image() { global $post; if (!has_post_thumbnail($post->ID)) { $attached_image = get_children( “post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1” ); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail($post->ID, $attachment_id); } } } } // Use it temporary to generate all featured images add_action(‘the_post’, ‘auto_featured_image’); // Used for new posts add_action(‘save_post’, ‘auto_featured_image’); add_action(‘draft_to_publish’, ‘auto_featured_image’); … Read more
You can try wp_get_attachment_image_src this for getting Feature Image URL. Here is the Full code. <?php function propertunity_featured_post() { $featured_post_id = 2860; $featured_post = get_post($featured_post_id); $featured_post_url = get_permalink($featured_post_id); $featured_post_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($featured_post_id, ‘thumbnail’) ); echo “<div class=”card”> <div class=”card-header” style=”background-color: #f8f8fc; overflow: hidden;”> <a href=”” . $featured_post_url . “”> <div class=”card__image” style=”background-image: url(” ” . … Read more
I believe you need to use set_post_thumbnail to actually set featured image: set_post_thumbnail($_POST[‘post_id’], $attachment_id);
(function($){ $(document).ready(function(){ var items = []; $.getJSON(‘https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolio&per_page=50&_embed’, function(response){ console.log(response); $.each(response, function(key,val){ //console.log(val._embedded[‘wp:featuredmedia’][0].source_url); items.push(”+”+ ”); }); }); }); }(jQuery)); //use variable array to push data
How to create thumbnails programmatically?
I think the problem is that you’re trying to get the metadata for an image without specifying which size you want the width and height from. $imgData = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) ); $width = $imgData[‘width’]; $height = $imgData[‘height’]; Instead try this: $imgID = get_post_thumbnail_id( get_the_ID() ); $imgURL = wp_get_attachment_image_src( $imgID, ‘full’ ); // now … Read more
Use the Following code, <?php // Get the Featured image ID $thumbnail_id = get_post_thumbnail_id( $post->ID ); $image_data = wp_get_attachment_image_src( $thumbnail_id, ‘full’ ); $image_url = $image_data[0]; $image_width = $image_data[1]; $image_height = $image_data[2]; // Caption $get_description = get_post( $thumbnail_id )->post_excerpt; // Extinsion $mime_type = get_post_mime_type( $thumbnail_id ); $mime_type = explode( “https://wordpress.stackexchange.com/”, $mime_type ); $extinsion = $mime_type[‘1’]; ?>