Bulk edit wordpress images alt and title attributes

You can use the ‘wp_get_attachment_image_attributes’ hook add_filter( ‘wp_get_attachment_image_attributes’, ‘image_attributes’, 20, 2 ); function image_attributes( $attr, $attachment ) { // Get post parent $parent = get_post_field( ‘post_parent’, $attachment ); // Get post title $title = get_post_field( ‘post_title’, $parent ); if ( is_single( $parent ) ) { $attr[‘alt’]=$title; } return $attr; } Or Check Out my new … Read more

Theme Customiser Image Control

The solution, needs a custom control object extending the original image control, and does an SQL query to grab the GUID and associated attachment ID on sanitisation. Not nice, kludgey, but it works $wp_customize->add_setting( ‘customimage’, array( ‘default’ => $default, ‘capability’ => ‘edit_theme_options’, ‘type’ => ‘option’, ‘sanitize_callback’ => array( ‘ICIT_Customize_Image_Control_AttID’, ‘attachment_guid_to_id’ ), ‘sanitize_js_callback’ => array( ‘ICIT_Customize_Image_Control_AttID’, … Read more

How to limit number of images being printer out in “Set Featured Image” pop up?

Update 1: After dived into core AJAX call, this filter will only happen on post.php page: add_filter(‘ajax_query_attachments_args’, function($query){ if ( isset($_POST[‘post_id’]) && !empty($_POST[‘post_id’]) ) { $query[‘posts_per_page’] = 10; // output 10 images only. } return $query; }); You can use ajax_query_attachments_args filter: add_filter(‘ajax_query_attachments_args’, function($query){ $query[‘posts_per_page’] = 10; // output 10 images only. return $query; }); … Read more

Use Media upload in custom widget on wordpress 3.5

Check if this works for you: Put this code in jQuery(document).ready( function(){ function media_upload( button_class) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery(‘body’).on(‘click’,button_class, function(e) { var button_id =’#’+jQuery(this).attr(‘id’); /* console.log(button_id); */ var self = jQuery(button_id); var send_attachment_bkp = wp.media.editor.send.attachment; var button = jQuery(button_id); var id = button.attr(‘id’).replace(‘_button’, ”); _custom_media = true; wp.media.editor.send.attachment = function(props, … Read more

Adding upload button in metabox

this is how I do to create upload button in metabox: FILE: template_dir/functions.php add this lines: wp_enqueue_script(‘custom-js’, get_template_directory_uri().’/js/custom-js.js’); // Add the Meta Box function add_custom_meta_box() { add_meta_box( ‘custom_meta_box’, // $id ‘Custom Meta Box’, // $title ‘show_custom_meta_box’, // $callback ‘post’, // $page ‘normal’, // $context ‘high’); // $priority } add_action(‘add_meta_boxes’, ‘add_custom_meta_box’); // Field Array $prefix = … Read more

getting uploaded SVG dimensions on front-end

I agree with Tom J Nowell on the use of SVG, but if the upload is an actual image, you can tap into the attachment attributes using, as you suggested, wp_get_attachment_image_src. Those dimensions are actually already recorded and stored when using the WP media uploader, it’s likely that the plugin you’re using makes use of … Read more

Resizing only featured images while uploading

You can simply set all unused image size attributes to 0 to stop WordPress generating them. Whilst this only applies for default image sizes, you can use filters to remove them. In general, WP stores all those sizes to generate images for in the global $_wp_additional_image_sizes. The following plugin uses a filter to remove sizes … Read more

Prevent image upload unless exact size

Haven’t tested it, but this should work: // check for file upload size // { if( !current_user_can( ‘administrator’) ) add_filter( ‘wp_handle_upload_prefilter’, ‘mdu_validate_image_size’ ); } add_filter(‘wp_handle_upload_prefilter’,’mdu_validate_image_size’); function mdu_validate_image_size( $file ) { if ( mime_content_type($file) == ‘application/zip’ ) { mdu_validate_zip_image_size($file); return $file; } $image = getimagesize($file[‘tmp_name’]); $minimum = array( ‘width’ => ‘800’, ‘height’ => ‘450’ ); $maximum … Read more

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