Add multiple images to a page sidebar
I would recommend using MetaBoxes. A nice tutorial is here: http://www.farinspace.com/wpalchemy-metabox/
I would recommend using MetaBoxes. A nice tutorial is here: http://www.farinspace.com/wpalchemy-metabox/
Use this in your theme’s functions.php: add_filter( ‘add_attachment’, ‘wpse_55801_attachment_author’ ); function wpse_55801_attachment_author( $attachment_ID ) { $attach = get_post( $attachment_ID ); $parent = get_post( $attach->post_parent ); $the_post = array(); $the_post[‘ID’] = $attachment_ID; $the_post[‘post_author’] = $parent->post_author; wp_update_post( $the_post ); }
I wonder if you want to modify the HTML of the inserted image, with the image_send_to_editor or get_image_tag filters? If that’s the case, then here’s one example: /** * Add the data-ext-link-title and data-ext-link-url attributes to inserted images. */ add_filter( ‘image_send_to_editor’, function( $html, $id, $caption, $title, $align, $url, $size, $alt ) { if( $id > … Read more
Solution for WordPress versions >= 4.7.4 (4.8) Ticket #31071 introduces patches with new filters to override three possible slow media queries, in the wp_enqueue_media() function: media_library_show_audio_playlist (@param bool|null) From the inline doc: Whether to show the button, or null to decide based on whether any audio files exist in the media library. media_library_show_video_playlist (@param bool|null) … Read more
To remove the From Computer tab header, you unset the type key from that array. However, this will (confusingly) not remove the tab content, and because this is the default tab it will show it even if the tab header for it is gone. To change the default tab you must hook into the media_upload_default_tab … Read more
@AboSami actually answered this question in an older post that was not showing up in my search diligence. While he was actually looking for something else his example code worked great. Here’s the script: <?php $post_id = $post->ID; if ( isset( $_POST[‘html-upload’] ) && !empty( $_FILES ) ) { require_once(ABSPATH . ‘wp-admin/includes/admin.php’); $id = media_handle_upload(‘async-upload’, … Read more
From comment: Let WordPress generate a file path and use that for the next steps: $upload = wp_handle_upload($filename, array(‘test_form’ => false)); $attach_id = wp_insert_attachment( $attachment, $upload[‘file’], $post_id ); wp_update_attachment_metadata( $attach_id, $attach_data );
It’s better to use get_children than get_posts. Here is a quick example that will work. This is in the form of a function that is defined in your plugin or in functions.php then use the function as a template tag. /** * Gets all images attached to a post * @return string */ function wpse_get_images() … Read more
I wanted to be able to add author information to my attachments and merged this code: http://www.billerickson.net/wordpress-add-custom-fields-media-gallery/ with the one you refer to. I Got it to work fully in the modal window via AJAX. The modified code is as follows: /** * Add Author Name and URL fields to media uploader * * @param … Read more
You can modify an existing media library image using wp_insert_attachment by setting the ID key in the parameter array. $attachment = array( ‘ID’ => $existing_library_attachment_id, ‘post_parent’ => $custom_post_id ); wp_insert_attachment( $attachment ); This will update the attachment post with ID $existing_library_attachment_id to have a post_parent value of $custom_post_id. However, the only thing this will affect … Read more