Better REST API Featured Images
Note: You probably do not need this plugin. The REST API already supports adding the query param ?_embed to your URL and the response will then include all “embedded media”, including the featured image, and the data you get there is exactly what this plugin gives you. The only reasons to use this plugin at this point are if you prefer to have the featured image data in a top level field in the response rather than among other embedded media in the _embedded field, and if you always want the featured image data in the response rather than having to ask for it with ?_embed. I still use this plugin because I do usually want both these things, but definitely give ?_embed a try before using this plugin. 🙂 Version 2 of the WordPress REST API returns a featured_media field (formerly featured_image) on the post object by default, but this field is simply the image ID. This plugin adds a better_featured_image field to the post object that contains the available image sizes and urls, allowing you to get this information without making a second request. It takes this: "featured_media": 13, And turns it into this: "featured_media": 13, "better_featured_image": { "id": 13, "alt_text": "Hot Air Balloons", "caption": "The event featured hot air balloon rides", "description": "The hot air balloons from the big event", "media_type": "image", "media_details": { "width": 5760, "height": 3840, "file": "2015/09/balloons.jpg", "sizes": { "thumbnail": { "file": "balloons-150x150.jpg", "width": 150, "height": 150, "mime-type": "image/jpeg", "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-150x150.jpg" }, "medium": { "file": "balloons-300x200.jpg", "width": 300, "height": 200, "mime-type": "image/jpeg", "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-300x200.jpg" }, "large": { "file": "balloons-1024x683.jpg", "width": 1024, "height": 683, "mime-type": "image/jpeg", "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-1024x683.jpg" }, "post-thumbnail": { "file": "balloons-825x510.jpg", "width": 825, "height": 510, "mime-type": "image/jpeg", "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons-825x510.jpg" } }, "image_meta": { "aperture": 6.3, "credit": "", "camera": "Canon EOS 5D Mark III", "caption": "", "created_timestamp": 1433110262, "copyright": "", "focal_length": "50", "iso": "100", "shutter_speed": "0.004", "title": "", "orientation": 1 } }, "post": null, "source_url": "http://api.example.com/wp-content/uploads/2015/09/balloons.jpg" }, The format of the response is nearly identical to what you would get sending a request to /wp-json/wp/v2/media/13 or using ?_embed. When no featured image has been set on the post the better_featured_image field will have a value of null. I’ve done some basic performance tests that indicate the difference in response times with and without this plugin to be about 10-15ms for a collection of 10 posts and 0-5ms for a single post. For me this is much faster than making a second request to /media/, especially for multiple posts. As of version 1.1.0, there is a filter better_rest_api_featured_image that allows you to add custom data to the better_featured_image field. The filter is directly on the return value of the function that returns the better_featured_image field. This can be used to do things like add custom image meta or an SVG version of the image to the response. Here’s an example of how you might use it: add_filter( 'better_rest_api_featured_image', 'xxx_modify_rest_api_featured_image', 10, 2 ); /** * Modify the Better REST API Featured Image response. * * @param array $featured_image The array of image data. * @param int $image_id The image ID. * * @return array The modified image data. */ function xxx_modify_rest_api_featured_image( $featured_image, $image_id ) { // Add an extra_data_string field with a string value. $featured_image['extra_data_string'] = 'A custom value.'; // Add an extra_data_array field with an array value. $featured_image['extra_data_array'] = array( 'custom_key' => 'A custom value.', ); return $featured_image; } This plugin is on on Github and pull requests are always welcome. 🙂
Top keywords
- image33×4.94%
- featured24×3.59%
- featured image18×2.69%
- api12×1.80%
- data10×1.50%
- field10×1.50%
- jpg10×1.50%
- media9×1.35%
- better7×1.05%
- response7×1.05%
- rest7×1.05%
- rest api7×1.05%
Topper System SEO
Free for the first 10.000 activations Case studies Take a look at some of our success stories! Topper System SEO is the most advanced SEO-friendly optimization system for WordPress websites. It is quick and easy to use, and it uses an innovative process to enhance and make more effective a keyword that you have established on each page. Pages optimized with the plugin can take advantage of the new CO2 Application service, which decreases the level of CO2 produced because the pages are lighter and faster to load. Topper System SEO offers a complete package of features, including: * Optimization of source code, images, and resource JS and CSS * Effective injection of favorite keyword * Smart image lazy-load * Anti-spam service * Cache support * CO2 Application These features can help you to: * Increase page loading speed * Exponentially increase natural visibility on Google, Bing, Yahoo, and Yandex for your favorite keywords * Increase the level of security with built-in anti-spam * Reduce your website’s carbon footprint Export and import of CSV files The new CSV export and import feature allows users to export all SEO optimization specifications for each page of their website into a CSV file. This file can then be imported into another website or used to create a backup of your SEO settings. Exporting CSV files is useful for the following reasons: * Backup SEO settings: Allows you to create a backup of your website’s SEO settings so you can restore them in case of problems. * Transfer SEO settings to another website: Allows you to transfer SEO settings from one website to another. * SEO settings analysis: allows you to analyze your website’s SEO settings to identify any problems or opportunities for improvement. Connection to ChatGPT The new ChatGPT connection feature allows users to use ChatGPT’s artificial intelligence to improve the writing of the title and description meta data of their web pages. Connecting to ChatGPT is useful for the following reasons: * Improved readability and relevance of title and description meta data: ChatGPT can generate meta data that is more readable and relevant to web pages, improving the likelihood of it appearing in search results. * Saves time and effort: ChatGPT can automate the process of writing meta data, freeing users to focus on other aspects of their SEO activity. Topper System SEO is suitable for all types of users, from less experienced to SEO professionals. In simpler terms: Topper System SEO is a WordPress plugin that helps you to improve your website’s search engine rankings and traffic for your target keywords. It does this by optimizing your website’s code, images, and content, as well as providing a number of other features, such as anti-spam and caching. Topper System SEO is easy to use and suitable for all types of users, from beginners to experts. Try Topper System SEO for free now Available in language: * العربية(β) * Deutsch (β) * English * Español (β) * Français (β) * עִבְרִית (β) * हिन्दी (β) * Italiano * 日本語 (β) * Latin (β) * Polski (β) * Português (β) * Русский (β) * 简体中文 (β) Api Center Topper System SEO www.toppersystem.com