Regex to turn embedded images in to attachments
Regex to turn embedded images in to attachments
Regex to turn embedded images in to attachments
Here is my working solution. The code is documented, so it should be clear what each function does. I pretty much use the wp_generate_attachment_metadata filter to create the needed images after the image has been uploaded. The generated images are listed in the metadata too, like any other intermediate image size. That way you can … Read more
Looking at @obmerks answer on https://stackoverflow.com/questions/12997698/delete-images-after-post you can simplify it with this: foreach ( $productIds as $productId ) { $child_atts = $wpdb->get_col(“SELECT ID FROM {$wpdb->posts} WHERE post_parent = $productId AND post_type=”attachment””); foreach ( $child_atts as $id ) wp_delete_attachment($id,true); } Note: as per documentation https://codex.wordpress.org/Function_Reference/wp_delete_attachment set the second parameter to true to force delete the attachment, … Read more
Finally by luck i found the answer by @Tomas function gallery_template_to_posts() { $post_type_object = get_post_type_object( ‘post’ ); $post_type_object->template = array( array( ‘core/gallery’, array( ‘linkTo’ => ‘media’, ) ), ); } add_action( ‘init’, ‘gallery_template_to_posts’ );
Users shouldn’t have to know anything about image sizes. Just have them upload as-large-as-needed images and your job is to get WordPress to do the rest. When a user uploads an image, WordPress will generate as many images as you’ve declared with add_image_size(). An example from the codex for your functions.php file: if ( function_exists( … Read more
Sure – php can definitely handle simple math like this. All you’d have to do is reference the numbers coming back from the wp_get_attachment_image_src call: <?php if ( has_post_thumbnail()) { $full_image_info = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘full’); $img_h = $full_image_info[1]; $img_w = $full_image_info[2]; $total_pixels = $img_w * $img_h ; $megapixels = round($total_pixels) /* see http://at2.php.net/manual/en/function.round.php — they … Read more
It actually depends upon how the image is shown in the template. If it is shown using a function like the_post_thumbnail() which returns complete html string to show image with alt then there should be no problem but if image is shown by only fetching URL then it depends how it is displayed . For … Read more
Try using PHP’s regular expression find/replace function—preg_replace()—in a filter on the the_content hook. function breezer_addDivToImage( $content ) { // A regular expression of what to look for. $pattern = ‘/(<img([^>]*)>)/i’; // What to replace it with. $1 refers to the content in the first ‘capture group’, in parentheses above $replacement=”<div class=”myphoto”>$1</div>”; // run preg_replace() on … Read more
(Answering my own question, with help from @brasofilo) WordPress 3.5 has a great new Media manager, and it no longer requires the Title to be filled in for images. It also no longer fills in the Title automatically when reorganizing images in a Gallery. It does, however, still fill in the Title with the image … Read more