How to crop image from image src in a specific size

WordPress has a function solely designed for this purpose. the attachment_url_to_postid() allows you to retrieve an attachment’s ID from it’s URL, which then you can use to get the post’s ID later. If you want to do it by writing a MySQL query, i would however prefer to suggest searching the file’s name in meta_value … Read more

Displaying images with relative paths in the editor

I had a client ask for that and it took a little while to get it but its simple: function change_mce_path_options( $init ) { $init[‘relative_urls’] = true; $init[‘document_base_url’] = get_bloginfo(‘url’); return $init; } add_filter(‘tiny_mce_before_init’, ‘change_mce_path_options’);

hook into completed image upload filter

WordPress’ media handling strikes me as scattered and inconsistent. I say that only to say that I can’t promise this will work in all cases. However, I think I’d use the add_attachment hook from wp_insert_attachment. You will get a post ID, so you will have to … retrieve the image src with wp_get_attachment_imge_src, probably, retrieve … Read more

How to wrap WordPress image captions inside H2, H3 tags?

You can hook into the filter img_caption_shortcode and replace the whole captioned image. Here I’ve copied the caption shortcode function from WP4.5, left the version used if your theme declares HTML5 support as it is (using figcaption) and modified the non-HTML5 version to use h2. function wpse_233354_img_caption_shortcode( $empty, $attr, $content = null ) { // … Read more

Insert an image into a post by API

You can set the uploaded image as the post thumbnail via, update_post_meta($post_id,’_thumbnail_id’,$attach_id); Example… if ($_FILES) { foreach ($_FILES as $file => $array) { if ($_FILES[$file][‘error’] !== UPLOAD_ERR_OK) { return “upload error : ” . $_FILES[$file][‘error’]; } $attach_id = media_handle_upload( $file, $post_id ); } } update_post_meta($post_id,’_thumbnail_id’,$attach_id); If you are uploading an array of images, then you … Read more

Which action hook can I use when a featured image has been selected

The set_post_thumbnail function uses the metadata functions to set the featured image. You have two actions to hook into that process: EDIT: The action hooks are now defined different Thanks @dalbaeb! update_postmeta, before the data is written into the database. Previously update_post_meta updated_postmeta, after the data is written into the database. Previously updated_post_meta SECOND EDIT: … Read more

add_image_size() zoom-crop

Currently, WordPress core image handling/thumbnail creation does not perform zoom-crop. If you need an intermediate image size to be created explicitly, you will need to ensure that you upload an image with equal or larger dimensions as the intermediate image size.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)