Image size filtering in Media uploader according to custom post type

Add following code in your themes functions.php file function theme_set_default_image_size() { global $post_type; $custom_image_size=”medium”; if($post_type == ‘news’) $custom_image_size=”news_image_size”; else if($post_type == ‘product’) $custom_image_size=”product_image_size”; else if($post_type == ‘service’) $custom_image_size=”service_image_size”; return $custom_image_size; } add_filter( ‘pre_option_image_default_size’, ‘theme_set_default_image_size’ );

Link to File URL by default

Answered a similar question on the .org forums very recently. To sum it up though.. Go to http://example.com/wp-admin/options.php (replace example.com with your website address) Scroll down the page until you see image_default_link_type Set that option to either file, post or to an empty value. Empty = No link File = Links to the file(what you … Read more

Displaying a featured image (only img url) as the img src?

Here are the functions you need to be aware of: http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id http://codex.wordpress.org/Function_Reference/wp_get_attachment_url http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src http://codex.wordpress.org/Function_Reference/wp_get_attachment_image Example sans size: echo wp_get_attachment_url(get_post_thumbnail_id()); Example with size: $image = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘large’); echo $image[0]; //as HREF in your A tag You can grab all of the gallery images as follows: $args = array( ‘order’=> ‘ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $post->ID, … Read more

Broken image multisite

After reading several topics about this issue I’ve found this: Issues with old WPMU installs If you installed WordPress MU in subfolder/subdirectory (not in root folder on your server >via ftp) and you have problem with image library, where thumbnails and images do not show, >you may need to manually add in rewrite rules for … Read more

Can’t Display Featured Image in RSS Feed

By default, RSS won’t display. You have to use RSS2. However this will help you. Paste it in your functions.php: function insert_thumbnail_into_feed() { global $post; if ( has_post_thumbnail( $post->ID ) ){ // replace thumbnail with yours $content=”<p>” .get_the_post_thumbnail( $post->ID, ‘thumbnail’ ) .'</p>’; } // get post content and replace feed content with // you can … Read more

how to base64 encode images in wordpress template

in your file functions.php in your template put this funcitons /** * @param $path * @return string * @author https://github.com/ozzpy */ function imageEncode($path) { $path = __DIR__.”https://wordpress.stackexchange.com/”.$path; $image = file_get_contents($path); $finfo = new finfo(FILEINFO_MIME_TYPE); $type = $finfo->buffer($image); return “data:”.$type.”;charset=utf-8;base64,”.base64_encode($image); } /** * @param $path * @return string * @author https://github.com/ozzpy */ function imageEncodePath($path) { $image … Read more

Loop through child images of a parent for a Nivo Slider

To get attached (i.e. child) images of a post, try using get_children(). e.g.: <?php $child_image_args = array( ‘post_mime_type’ => ‘image’, ‘post_parent’ => $postID, ‘post_type’ => ‘attachment’ ); $child_images = get_children( $child_image_args ); ?> Which returns an associative array of child images. Then, just loop through them, e.g. using wp_get_attachment_image(), to output. e.g.: <div id=”nivoslider”> <?php … Read more

Open the attachment details modal

Unfortunately the logic of the attachment details isn’t made to be used standalone – it requires the grid that opens it. You can however use the get_media_item( attachment_id ) method to receive the HTML of the form for modifying images: https://developer.wordpress.org/reference/functions/get_media_item/

Adding custom image size to the media image editor

As far as i know it is possible with image_size_names_choose hook (see https://codex.wordpress.org/Plugin_API/Filter_Reference/image_size_names_choose). Example: // add your custom size function my_setup_image_sizes() { add_image_size( ‘wide-image’, 900, 0); } add_action( ‘after_setup_theme’, ‘my_setup_image_sizes’ ); // add custom size to editor image size options function my_editor_image_sizes( $sizes ) { $sizes = array_merge( $sizes, array( ‘wide-image’ => __( ‘Image 900px … Read more

Is it possible to prevent users from uploading small images?

Here you go: if(!current_user_can(‘delete_others_posts’)){ /*Handling wp media uloads*/ add_filter(‘wp_handle_upload_prefilter’,’lets_handle_img_width’); function lets_handle_img_width($file) { $img = getimagesize($file[‘tmp_name’]); $width = $img[0]; if ($width < 350){ $file[‘error’] = “Image is small too small. Get something of width more than 350px.”; } return $file; } } Check official documentation about wp_handle_upload_prefilter.