Using Add_image_size when adding image in post

You also need to add it to image size chooser.You can do so using the filter image_size_names_choose. add_filter( ‘image_size_names_choose’, ‘wpse_228675_custom_size’ ); function wpse_228675_custom_size( $sizes ) { return array_merge( $sizes, array( ‘image_horizontal’ => __(‘Custom image size’), ) ); }

change the $content_width

Is there are better way to change this (annoying) variable please? The Twenty Sixteen theme provides you with the twentysixteen_content_width filter, where the default is 840. To modify it you should be able to use this within your child theme’s functions.php file: add_filter( ‘twentysixteen_content_width’, function( $content_width ) { // Override the default 840 content width … Read more

How Do I Delete All The Images from WordPress

You could try the following, I havent tested it, so look out for typos or errors: $all_posts = get_posts(array( ‘numberposts’ => – 1, ‘post_status’ => ‘any’, ‘post_type’ => get_post_types(”, ‘names’) , )); foreach($all_posts as $all_post) { delete_post_media($all_post->ID); } function delete_post_media($post_id) { if (!isset($post_id)) return; elseif ($post_id == 0) return; elseif (is_array($post_id)) return; else { $attachments … Read more

limit file type and file size using media_handle_upload

Use PHP // Check that the nonce is valid, and the user can edit this post. if (isset( $_POST[‘my_image_upload_nonce’] ) && wp_verify_nonce( $_POST[‘my_image_upload_nonce’], ‘my_image_upload’ ) ){ // Input type file name $image_input_name=”my_image_upload”; // Allowed image types $allowed_image_types = array(‘image/jpeg’,’image/png’); // Maximum size in bytes $max_image_size = 1000 * 1000; // 1 MB (approx) // Check … Read more

Display post image with fancybox

When you echo something, you need to be echoing the variable. You are using the_post_thumbnail_url, which in itself is already an echo statement. You should be using get_the_post_thumbnail_url instead. echo “<a class=”fancybox” rel=”group” href=”” . get_the_post_thumbnail_url( get_the_ID(), “full’ ) . “‘>”; EDIT: Also, missing the $post_id, fixed to include it in the function

Add Small Image Size to Media Settings

You can register a new image size by using add_image_size() add_image_size( string $name, int $width, int $height, bool|array $crop = false ) Parameters $name (string) (Required) Image size identifier. $width (int) (Required) Image width in pixels. $height (int) (Required) Image height in pixels. $crop (bool|array) (Optional) Whether to crop images to specified width and height … Read more