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

Customizing gallery shortcode in 3.5

Make sure that the javascript loaded by your load-scripts.php is waiting for the document to finish loading before attaching all of the listeners. When you created a separate function the code ran only a tiny bit earlier, but it was probably early enough for the elements to finish loading and the listeners to properly attach.

how do i create a downloadable gallery with image descriptions?

This is not a bug, it’s a style matter (that maybe renders the Question off-topic). Using the Nextgen Download Gallery plugin, this can be solved by simply applying the following rule to your theme’s style.css file: .ngg-gallery-thumbnail { width: 120px; } Adjusting the width to match your theme’s design. And even the following rule, if … Read more

Detect if is image unattached

For unattached images, the post_parent column in the wp_posts table, has the value of 0. Your gallery shortcode in that case is: which means you are calling get_children() with post_parent as 0. You can e.g. use the gallery shortcode callback gallery_shortcode() directly: if( $parent_id = $post->post_parent ) { echo gallery_shortcode( [ ‘id’ => (int) $parent_id, … Read more

Allowing for multiple template views on the Gallery Settings page when using the Visual Editor

It appears that the templates live in script form <script type=”text/html” id=”tmpl-my-custom-gallery-setting”> To render the above template would require wp.media.template(‘my-custom-gallery-setting’)(view) Since we’re replacing the template: logic then all we need to do is store a list of template IDs. if (!wp.media.gallery.templates) wp.media.gallery.templates = [‘gallery-settings’]; wp.media.gallery.templates.push(‘my-custom-gallery-setting’); Then loop through all available views wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({ template: … Read more

How to get the first image gallery of a product in woocommerce in a loop

Along with the product thumbnail (I’m assuming you have this), what you need is a list (array) of the product images – WooCommerce has such methods, eg $product->get_gallery_attachment_ids(). You can grab the first ID in the array and use it to fetch the single image using wp_get_attachment_image(), or wp_get_attachment_url(), etc., then use that as an … Read more

First three images in post excerpt

You can do this pretty easily using the do_shortcode function. Check if an instance of exists in your post content. Here’s a simple function to drop in functions.php that checks the current post’s content for the gallery shortcode: function gallery_shortcode_exists(){ global $post; # Check the content for an instance of with or without arguments $pattern … Read more