WordPress PNG compression issue

I'm having issues with images getting badly compressed when uploaded to my site. It's not an issue with photographs, but is very noticeable for images with solid blocks of colour and text. I've uploaded a PNG with a solid grey background overlaid with white text, and it's being badly compressed when WordPress resizes it to the various alternative sizes. Original image Large featured image size Unfortunately I don't have enough reputation to post more than 2 links, but you can …
Category: Web

Get featured image and additional posts thumbnail Wordpress REST API

I want to use the REST API of wordpress to build a new version of a custom theme. I'm able to get the json response of a particular category, but I need to find a way to obtain also the featured image or the second post thumbnail registered using a plugin, so I can use them in the layout. Is this possible without using a plugin? here is the code I'm using for testing: <script> (function($){ $(document).ready(function(){ $.getJSON('https://localhost/wordpress/wp-json/wp/v2/posts?category_name=portfolio&per_page=50&_embed', function(response){ console.log(response); …
Category: Web

Add Play Icon on thumbnail overlay for video post types

i was thinking if there was anyway to add a okay icon overlay for video post types, i already came up with a code that allows me set up a default thumbnail if post has no thumb, sample code below. <div class="img-responsive"> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('big-grid-one-image'); ?></a> <?php else : ?> <img src=" <?php echo get_template_directory_uri (); ?>/img/no-thumb/acardio-548px-450px.png" /> <?php endif; ?></div>
Category: Web

Bulk-add featured images in posts with no featured image

I have a site with loads of posts (news items). Some posts don't have featured images yet. Adding the images to those posts (few hundreds) is a tedious task. We basically want to add 1 and the same image to all the posts without a featured image. Is there a way to do this in bulk? Like ADD 'this image' to ALL 'posts' (not pages) WHERE 'featured_image' is empty. I really hope there's a plugin for that. Can't find it …
Category: Web

Can't get or display post thumbnail in wordpress

i'm working on a WordPress plugin and i'm trying to display/get the post thumbnail below the post on my "Related posts" part. I tried many things which are supposed to work but not for me ... here is the code (on my plugin.php file): add_theme_support( 'post-thumbnails', array( 'post', 'page' ) ); if ( has_post_thumbnail() ) { echo ('there is a thumbnail'); echo get_the_post_thumbnail(get_the_ID(), "thumbnail"); // nothing echo get_the_post_thumbnail(); // nothing echo var_dump(get_the_post_thumbnail(get_the_ID(), "thumbnail")); //string '' (length=0) echo var_dump(get_the_post_thumbnail()); //string '' …
Category: Web

set and unset the custom field value

While showing all the posts together in admin panel, I have a custom column 'Featured Image'. And this column has a value YesOrNO. To set the column name : I have inside functions.php: function set_column_heading($defaults) { $defaults['featured_image'] = 'Featured Image'; return $defaults; } add_filter('manage_posts_columns', 'set_column_heading'); In order to set the column value, I have : function set_column_value($column_name, $post_ID) { if ($column_name == 'featured_image') { $post_featured_image = get_featured_image($post_ID); if ($post_featured_image) { echo 'YesOrNO'; } } } function get_featured_image($post_ID) { $post_thumbnail_id = …
Category: Web

WordPress stopped generating image thumbnails after changing hosting environment

I moved my WP website from shared hosting, to Digital Ocean LEMP stack droplet. I noticed that thumbnails aren't generated any more for new post featured images, I also tried manually regenarating thumbnails for specific images, it succeeds but nothing generated. I tried deactivation of the Force Regenerate Thumbnails plugin and activating it again, but still no luck. Any ideas?
Category: Web

Child Theme not overwriting Parent theme php file

I'm new to Wordpress and how Child themes work. My child theme I am trying to overwrite two files in sub-directories. I've copied the parent files and edited them in child theme but changes are not reflected in parent theme. I'm trying to change the code for feature image sizes. I successfully changed the code in parent to test it and it works. But child theme isn't overriding it. /public_html/wp-content/themes/sahifa/framework/functions/theme-functions.php /public_html/wp-content/themes/sahifa-child/framework/functions/theme-functions.php /public_html/wp-content/themes/sahifa/framework/parts/related-posts.php /public_html/wp-content/themes/sahifa-child/framework/parts/related-posts.php Other question I had was do I …
Category: Web

Editing featured image

How can I edit the featured image? Usually I upload the image in media, there is one option which says "use as a featured image". This works fine but the output image is badly cropped. I want to know how can I manually crop it (150 x 150) and use that a featured image?
Category: Web

Get the first image from post content (eg.: hotlinked images)

I am using this code directly from the codex. function echo_first_image ($postID) { $args = array( 'numberposts' => 1, 'order'=> 'ASC', 'post_mime_type' => 'image', 'post_parent' => $postID, 'post_status' => null, 'post_type' => 'attachment' ); $attachments = get_children( $args ); //print_r($attachments); if ($attachments) { foreach($attachments as $attachment) { $image_attributes = wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) ? wp_get_attachment_image_src( $attachment->ID, 'thumbnail' ) : wp_get_attachment_image_src( $attachment->ID, 'full' ); echo '<img src="'.wp_get_attachment_thumb_url( $attachment->ID ).'" class="current">'; } } } I call it within the loop like this …
Category: Web

Use AJAX to fetch Current Post Thumbnail for Wordpress when Uploaded throughMedia Uploader Frontend

i Use WordPress Media Uploader on Frontend to allow users to upload Thumbnail for there UGC site. I also show a Preview of the Image on Frontend. When a user clicks the button the Media Uploader opens user uploads image, sets it as Featured Image and we are good. But, the Image Preview still shows old Image. I have a WordPress Site, based on User Generated Content, where people can create posts via a Frontend Form. When A user updates …
Category: Web

How to check if user is uploading/setting an image as a featured image?

I'm making a limitation for image upload based on @brasofilo excellent snippet. In short, it limits user to only uploading image with minimum dimension. However I want to apply this only when user is uploading a featured image. I tried using $pagenow as a conditional, global $pagenow; if ($pagenow == 'media-upload.php') add_filter( 'wp_handle_upload_prefilter', 'wpse_28359_block_small_images_upload' ); But it doesn't work. Any idea here?
Category: Web

Query posts only with featured image

I want to query 6 posts, but only those which have a featured image attached. I am using meta_key method for this with WP_Query as such: $args = array( 'post_type' => 'post', 'meta_key' => '_thumbnail_id', 'post_count' => 6 ); $query = new WP_Query($args); Followed by <?php while($query->have_posts()) : $query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_post_thumbnail('thumbnail'); ?> <?php endwhile; ?> This doesn't seem to work. The query is returning more than 6 posts and also those which don't have a featured …
Category: Web

Need to add a post’s featured image to a section on the frontpage

It looks like I will need to create custom PHP code for this and either add it to my includes directory within a custom PHP file, or to the functions.php file. I need the ability to use a featured image in a post and be able to also dynamically display that same image in a gallery on the frontpage. I am not a PHP master by any means, but I know a bit to get around. My guess is I …
Category: Web

mySQL database size large, but tables size less

I have my site hosted with NetworkSolution, and they have a sql database size limit of 300MB. IF the size exceeds this limit we cannot access the wordpress admin dashboard. So currently its showing 441MB, and its overlimit. And they are force me to upgrade the database size to 1GB for 120$/yearly. But previously I had all tables size totaling to 45MB, but the database size was 321MB, and I had to request them to grant me access, so they …
Category: Web

wordpress responsive image srcset not working

I'm trying use wordpress core responsive image feature but it's not adding srcset to image. Here is th my codes I have a div w=370px h=280px now I added image sizes if(function_exists('add_image_size')){ add_image_size( 'imagebox', 370, 280, true ); add_image_size( 'imagebox-2x', 840, 560, true ); add_image_size( 'imagebox-3x', 1110, 840, true );} And calling it inside the loop like this the_post_thumbnail('imagebox-2x'); it's adding only image like this 2x version without srcset <img width="840" height="560" src="http://localhost/starter/wp-content/uploads/2018/10/04004_theblackandwhiterocky_2560x1600-840x560.jpg" class="attachment-imagebox-2x size-imagebox-2x wp-post-image" alt=""> If I remove …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.