insert image alongwith with custom data via a frontend form

For Image uploads you can use wp_handle_upload(). Adding attachments can be done through wp_insert_attachment(). The association between attachment and your costing item can be achieved through update_post_meta(). Aside: Meta keys starting with an underscore _ are not showing up in WordPress UI. You code could be looking like this: <?php $my_costing_id; /* contains the id … Read more

Random background image showing on website per click/load

If you want to use add_image_size, your images must be uploaded as WordPress attachments, and not only be present inside a specific folder. So first of all register your custom size: add_action( ‘after_setup_theme’, ‘gmrb_background_image_size’ ); function gmrb_background_image_size() { // using WP 3.9 crop position // see https://codex.wordpress.org/Function_Reference/add_image_size#Crop_Mode add_image_size( ‘gmrb_background’, 1500, 1500, array( ‘center’, ‘center’) ); … Read more

Resize images in batch

Ankit you can re-size images by using this script via terminal: <?php ini_set(‘max_execution_time’, 0); set_time_limit(0); require_once(‘./wp-load.php’); require_once( ‘./wp-admin/includes/admin.php’ ); for($i=0;$i<=500;$i++){ $attachments =& get_children(array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, ‘numberposts’ => 50, ‘paged’ => $i, ‘post_status’ => null, ‘post_parent’ => null ), ARRAY_A); foreach ( $attachments as $attachment ) { $image = get_post($attachment[‘ID’]); $original_size_path = … Read more

Get all image IDs from the Media Library

From my understanding I can’t get the image IDs directly from wordpress. I have to first get their URLs and then extract their IDs. If there is a more efficient way to do this please let me know. I’m not sure I follow you there, but did you try this: $ids = get_posts( array( ‘post_type’ … Read more

Display image for first sticky post only

Try this : <ul> <?php $args = array( ‘category_name’ => ‘महाराष्ट्र’, ‘post__in’ => get_option( ‘sticky_posts’ ), ‘showposts’ => ‘6’, ); $the_query = new WP_Query( $args ); $count = 1; while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <li> <?php if ( 1 == $count ): ?> <div class=”thumbnail_class”><a title=”<?php the_title(); ?>” href=”https://wordpress.stackexchange.com/questions/150086/<?php the_permalink() ?>” … Read more

Google Page Speed Insights – Optimize Images

First, don’t let Google Insights drive you to chase an ROI that might not be there. Maybe for 1M of image data improvement, it is worth looking into – but after awhile that tool will have you minifying 1K css files to save 100 bytes. Second, regarding images – don’t just blindly reduce (‘compress’…really a … Read more

Getting thumbnail of uploaded image

Where are you attempting to get the image? That should be the correct function: global $post; $image = get_the_post_thumbnail( $post->ID ); It will return an array of all the image sizes for that given image. You can then grab the image size out of the array, or better yet pass in a specific image size … Read more

Make featured image be shareable across multiple pages?

You could easily do this by hooking into the save_post action and updating the featured image custom field. In your functions.php file, add the following code: function interit_featured_image( $post_id ) { // Get Parent ID $parent_id = wp_get_post_parent_id( $post_id ); // Only proceed if this page has a parent if ($parent_id != 0) : // … Read more