Why wordpress doesn’t generate thumbnails?
I found the problem. For some reason it was a JPEG file’s issue. I recreated all the JPEGs and now it generates the thumbnails…
I found the problem. For some reason it was a JPEG file’s issue. I recreated all the JPEGs and now it generates the thumbnails…
You can use the remove_post_type_support for your requirement. In your case, you remove post thumbnail if specific page template is not selected. function remove_post_thumb(){ if (isset($_GET[‘post’])) { $post_id = $_GET[‘post’]; } else if (isset($_POST[‘post_ID’])) { $post_id = $_POST[‘post_ID’]; } else { return; } $template_file = get_post_meta($post_id, ‘_wp_page_template’, TRUE); if ($template_file != ‘page-your-template.php’) { remove_post_type_support(‘page’, ‘thumbnail’); … Read more
Create a php script ( fpw-swap-thumbnails.php ) with the code below and put it in root of your site: <?php // load WordPress environment require( ‘wp-load.php’ ); $args = array( ‘posts_per_page’ => -1, ‘post_type’ => array( ‘post’, ‘page’ ), ‘post_status’ => ‘publish’ ); // get all published posts of type specified in $args $posts = … Read more
jQuery( document ).ready(function() { jQuery(“figure”).addClass(“wp-caption”); }); You could use jQuery to add a class.
Get Post thumbnail without width/height attribute
So, I finally noticed that what I was doing, was returning an array, and that I needed the [0] of that array. The code is on the ugly side, but it works. <?php $thumb_id = get_post_thumbnail_id(); $small_screen = wp_get_attachment_image_src($thumb_id,’small-screen’, true); $medium_screen = wp_get_attachment_image_src($thumb_id,’medium-screen’, true); $large_screen = wp_get_attachment_image_src($thumb_id,’large-screen’, true); $extra_large_screen = wp_get_attachment_image_src($thumb_id,’extra-large-screen’, true); ?> – <div … Read more
global $wpdb; $children = get_posts(‘post_type=event&numberposts=1’); foreach ($children as $child) { $origParentID = get_post_meta($child->ID, ‘mainpictureid’, true); $parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), ‘http://localhost/wp-content/uploads/2015/08/’.$origParentID.’.jpg’ ); $attachment = $wpdb->get_col( $wpdb->prepare( “SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;”, $parsed_url[1] ) ); set_post_thumbnail( $child->ID, $attachment[0]); }
Finally found the issue: I was using a filter in my site specific plugin to remove image attributes. Somehow it also deleted the full image URL. add_filter( ‘post_thumbnail_html’, ‘remove_img_attributes’, 10 ); Removing that filter solved the issue.
Do not use $post_id. From this answer by @s_ha_dum (which you should go and read). $post_id is a variable name used commonly to refer the post ID, but it isn’t a Core variable the way that $post is. In the context as in your question, you would want to use $recent[“ID”] (which will hold the … Read more
Its certainly not a few liner code. So its better to use a Feature Gallery plugin. I just tried that which works perfectly fine and you can use below code to get the images in Featured Gallery. <?php $galleryArray = get_post_gallery_ids($post->ID); foreach ($galleryArray as $id) { ?> <img src=”https://wordpress.stackexchange.com/questions/205062/<?php echo wp_get_attachment_url( $id ); ?>”> <?php … Read more