How do I add text or message above the featured image area in gutenberg for a CPT

Try this: function wrapPostFeaturedImage( OriginalComponent ) { const currentPostType = wp.data.select( ‘core/editor’ ).getCurrentPostType(); // Do nothing, if the post type is not rt_brands. if ( ‘rt_brands’ !== currentPostType ) { return OriginalComponent; } return function( props ) { // Your code here. }; } You can also: Conditionally add your filter: // Check if the … Read more

How to get a page’s featured image through REST API?

Maybe because the custom REST field (fimg_url) was only being added to posts of the post type and yet your request was for Pages, i.e. posts of the page type.. so try changing the register_rest_field( array(‘post’) to register_rest_field( array(‘post’, ‘page’). See https://developer.wordpress.org/reference/functions/register_rest_field/#parameters. But actually, you can use the _embed parameter to have the full media … Read more

How do I display a PDF thumbnail as a link to the PDF without uploading the image

The PDF images created by wordpress are stored within the PDF attachment object metadata. [ { “id”: 121, “media_type”: “file”, “mime_type”: “application/pdf”, … “media_details”: { “sizes”: { “full”: { … “source_url”: “<domain>/wp-content/uploads/document-name-pdf.jpg” } } ] Extracting the image from the PDF Adding an image block or adding a featured image to a post requires an … Read more

Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?

Try using JavaScript to handle this situation. The script should run when a user attempts to upload an image, and if the image upload fails, it will remove the associated UI elements (including that stubborn loading bar). Here’s a quick code: jQuery(document).ready(function($) { wp.Uploader.prototype.init = function() { this.uploader.bind(‘BeforeUpload’, function(uploader, file) { uploader.settings.multipart_params = { …uploader.settings.multipart_params, … Read more

How to add year and month path to old attachment images?

If you want to change the post thumbnail URL, use the filter wp_get_attachment_url; Try to follow the next code: // NAV: Change the url for thumbnail for post function wpcoder_change_post_thumbnail_url($url, $post_id) { if (strpos($url, ‘img/uploads/’) !== false) { $year = date(‘Y’); // Year folder $month = date(‘m’); // Month folder $url = str_replace(“img/uploads/”, “app/uploads/’.$year.”https://wordpress.stackexchange.com/”.$month.’/”, $url); … Read more

Second featured image only shows in metabox preview after saving a post in the wordpress editor

The issue you’re experiencing, where the image preview in the meta box doesn’t update immediately when you change the second featured image, is likely due to the way the image preview is being handled in your jQuery code. To resolve this, you need to ensure that the image preview updates in real-time as soon as … Read more

How to get Custom Post Type (CPT) Archive Page’s Posts Featured Images Preload in header.php

You can access the current query on a custom post type archive page with global $wp_query;. By using the global variable which holds the current query, you don’t need to do an additional query. To keep your header.php file cleaner, you could use actions and callback functions placed in your functions.php file to put the … Read more