Get featured image and additional posts thumbnail WordPress REST API

(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

Show thumbnail depending on image width

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

How to show Thumbnail size, caption, extension in WordPress?

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’]; ?>

Get featured image from post on RSS feed

I just found the right solution: function rss_post_thumbnail($content) { global $post; if(has_post_thumbnail($post->ID)) { $output=”<p>” . get_the_post_thumbnail($post->ID) . ‘</p>’; } return $output . $content; } add_filter(‘the_excerpt_rss’, ‘rss_post_thumbnail’, 20, 1); add_filter(‘the_content_feed’, ‘rss_post_thumbnail’, 20, 1);

Adding guiding text to the ‘Featured Image’-box in the backend

If you are using the Classic Editor of wordpress, there is a function for this: https://developer.wordpress.org/reference/hooks/admin_post_thumbnail_html/ So the code would be (example from link): function filter_featured_image_admin_text( $content, $post_id, $thumbnail_id ){ $help_text=”<p>” . __( ‘Please use an image that is 1170 pixels wide x 658 pixels tall.’, ‘my_textdomain’ ) . ‘</p>’; return $help_text . $content; } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)