How to get full absolute url for post attachment?

esc_attr() might not be necessary on the url retrieved by wp_get_attachment_image_src. I have referred to a code example from the WordPress Codex page on wp_get_attachment_image_src and adapted the following code that works for me. global $post; $thumbnailSrc = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘medium’); if ( $thumbnailSrc ) : echo ‘<meta property=”og:image” content=”‘.$thumbnailSrc[0].'”>’; endif; Edit: Since you are using … Read more

How to display featured images for all posts with certain taxonomy label?

Something quite rough that needs improvement but can give you a starting point, if I’ve understood your needs: use [dr] as shortcode marker where you want function my_dream_shortcode($atts, $content = null) { ob_start(); ?> <ul> <li class=”button” onClick=”get_data(‘corporate’)”>Corporate</li> <li class=”button” onClick=”get_data(‘sales’)”>Sales</li> <li class=”button” onClick=”get_data(‘support’)”>Support</li> </ul> <div class=”my_plugin_result”></div> <style> li.button{ list-style:none; padding:4px 10px; background-color:cadetblue; margin:10px; float:left; … Read more

Change post featured image on hover

You can add a custom field to you team page, call it “second_picture”, or whatever you want, and add the code <div class=”box”> <div class=”rounded-circle” style=”background-image:url(‘<?php the_post_thumbnail_url(‘full’); ?>’)” id=”staff-pic”> <div class=”second-picture” style=”background-image:url(<?php the_field(‘second_picture’); ?>)”></div> </div> <h3 class=”team-name”><?php the_title(); ?></h3> <p class=”description text-center”><?php echo get_the_content(); ?></p> <div class=”social”><a href=”#”><i class=”fab fa-facebook”></i></a><a href=”#”><i class=”fab fa-twitter”></i></a><a href=”#”><i class=”fab … Read more

How to retrieve the post featured image (thumbnail) ID in Gutenberg blocks?

I think you’re looking for: const featuredImageId = wp.data.select( ‘core/editor’ ) .getEditedPostAttribute( ‘featured_media’ ); to get the ID of the featured image and then for the corresponding media object: const media = featuredImageId ? wp.data.select( ‘core’).getMedia( featuredImageId ) : null; See e.g. here in the post featured image component: https://github.com/WordPress/gutenberg/blob/57c2ab37a872b63de215205458336b7fd6c9739d/packages/editor/src/components/post-featured-image/index.js#L105

Add instructions to featured image

WordPress has a hook for that. Here is a sample code: function featured_image_dimensions( $content, $post_id, $thumbnail_id ){ $help_text=”<p>” . __( ‘recommended dimensions – H980px by W450px’, ‘my_domain’ ) . ‘</p>’; return $help_text . $content; } add_filter( ‘admin_post_thumbnail_html’, ‘featured_image_dimensions’, 10, 3 ); Add this code to your functions.php and you should be good to go.

Post Thumbnails multiple sizes

Simply naming the size in the functions file is not enough to get the sizes to work: To call a custom size that you added do this: <?php the_post_thumbnail(‘category’); ?> I see you set_post_thumbnail_size(200, 200, true) which you don’t need to do if you’re also naming a post thumnail size the same sizes for homepage. … Read more