Disallow img tag in comments?

You can strip images on display pretty easily. add_filter( ‘comment_text’, function($comment) { $allowed_html = array( ‘a’ => array( ‘href’ => array(), ‘title’ => array() ), ‘br’ => array(), ’em’ => array(), ‘strong’ => array() ); return wp_kses($comment, $allowed_html); } ); That will strip any tags not listed in the provided array. To specifically strip images … Read more

Update Attached Image Size after Import

I’ve just had this or a very similar problem (I didn’t use the WP export tool, but instead did a manual migration from one environment to another). As far as I can tell, the problem occurs because of how WP stores the thumbnail data in the the wp_postmeta table (with the key ‘_wp_attachment_metadata’). This data … Read more

If Media Type .GIF

I’m not quite sure you’re using the wp_check_filetype() correctly. I just successfully tried the following to determine if the post thumbnail ext was jpg or not: $url = wp_get_attachment_url( get_post_thumbnail_id( ) ); $filetype = wp_check_filetype($url); if ($filetype[ext] == ‘jpg’) { echo ‘this is gif’; } else { echo ‘this aint gif’; } You probably know … Read more

How to Delete all Unused photos Function

As a rule, I suggest you try to stick as much as possible to WordPress core functions when modifying the database, as they will handle associated data automatically – e.g. delete associated post meta, associated taxonomy info, etc. (Woocommerce stores product image data as product post_meta, see below for details.) This might slow things down … Read more

Removing height and width from images with a caption

Here is another possibility, it alters the image markup when you select an image to add to your content in the editor add_filter( ‘image_send_to_editor’, ‘remove_img_attribute’, 10, 8 ); function remove_img_attribute( $html, $id, $caption, $title, $align, $url, $size, $alt ) { $imagetpl=”<figure> <a href=”https://wordpress.stackexchange.com/questions/129666/%s” title=”https://wordpress.stackexchange.com/questions/129666/%s”><img src=”https://wordpress.stackexchange.com/questions/129666/%s” alt=”https://wordpress.stackexchange.com/questions/129666/%s” class=”img-responsive %s” /></a> %s </figure>”; $figcaption = (!empty($caption)) ? … Read more

Add an attribute to attachments

This can be done with two filters, attachment_fields_to_edit and attachment_fields_to_save, which do exactly what their names suggest. Let’s say you wan to add a source field. First, generate the field and fill it with its current value if that exists: function wpse133608_add_attachment_location_field( $form_fields, $post ) { $field_value = get_post_meta( $post->ID, ‘source’, true ); $form_fields[‘source’] = … Read more

Site migration – some images not displaying in Media Library

I highly recommend updating all of your URLS. This can be done either with a word press plugin such as Velet Blues Update URLS Or via your SQL database: UPDATE wp_posts set post_content=REPLACE(post_content, ‘www.live.com/’, ‘www.test.com/’); note* images are uploadeded as posts in your database.* ( wp_posts table with a post_type of “attachment”. )

Large image size stuck on old value, even for new images

Find the actual large version of the image file (i.e., wp-content/uploads/2014/03/my-image-1024×576.jpg) and see if in fact it has the smaller dimensions or if it is just being rendered that way in your theme. If the large version is in fact 1024px wide, then the filter is working. Make sure you are referencing the right image … Read more