Displaying All Parent Pages as Featured Images

To get all the “root” pages of a site: $args = array( ‘post_type’ => ‘page’, ‘child_of’ => 0, ); $pages = get_pages( $args ); foreach( $pages as $page ) { if( has_post_thumbnail( $page->ID ) { $imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘large’ ); $imgwidth = $imgdata[1]; // thumbnail’s width $imgheight = $imgdata[2]; // thumbnail’s height } } … Read more

Always generate thumbnail after sideloading image

You’ll have to use wp_generate_attachment_metadata and wp_update_attachment_metadata to do this. // sideload it into wordpress (generates various sizes) $thumbid = media_handle_sideload( $file_array, $post->ID ); if ( is_wp_error($thumbid) ) { // deal with error here } // If this function is undefined in the environment where it is to be used, // such as within a … Read more

How to remove featured images from posts

Use Developer tools in Google Chrome and see what section is responsible for displaying the featured image on post page. Open page.php or single.php (relevant file responsible for generating single page) and delete that code. Keep a backup of the file before making any changes 🙂

Link from Thumbnail to Post not working

You probably have more than one query in your page, let’s make sure we are working with this query: <?php $carouselPosts = new WP_Query(); $carouselPosts->query(‘showposts=3’); // checking if there are posts to show if($carouselPosts->posts){ foreach ($carouselPosts->posts as $carouselPost) { echo ‘<a href=”‘. get_permalink($carouselPost->ID). ‘”>’; echo ‘<div class=”recentpostthumbnail”>’; echo get_the_post_thumbnail($carouselPost->ID,array(70,70)); echo ‘</div>’; echo ‘</a>’; $excerpt = … Read more

WordPress auto picking featured image

You need to create a function for that. Use this code below in your functions.php file and it will add a featured image automatically: /* Generate Featured Image Automatically */ function autoset_featured() { global $post; $already_has_thumb = has_post_thumbnail($post->ID); if (!$already_has_thumb) { $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) … Read more

Change get_post_thumb responsively?

You can do this by using conditionals for mobile ie: wp_is_mobile() Define both the sizes like add_image_size( ‘featured-cat’, 248, 110, true ); //featured-cat add_image_size( ‘featured-cat-mobile’, 200, 80, true ); //featured-cat mobile and edit the code like the below:– <?php echo ‘<div class=”featured-thumbnail”>’; if( wp_is_mobile() ) the_post_thumbnail(‘featured-cat-mobile’,array(‘title’ => ”)); else the_post_thumbnail(‘featured-cat’,array(‘title’ => ”)); echo ‘</div>’; ?>