Append Media/Attachment IDs to Gallery Shortcode HTML Output

WordPress already does this, in at least 2 ways For example, here is an <img> tag from a standard gallery block on my local test install: <img src=”http://one.wordpress.test/wp-content/uploads/2020/03/80694475_10220097889178767_6336534537924771840_n.jpg” alt=”” data-id=”15″ data-full-url=”http://one.wordpress.test/wp-content/uploads/2020/03/80694475_10220097889178767_6336534537924771840_n.jpg” data-link=”http://one.wordpress.test/?attachment_id=15″ class=”wp-image-15″ srcset=”http://one.wordpress.test/wp-content/uploads/2020/03/80694475_10220097889178767_6336534537924771840_n.jpg 750w, http://one.wordpress.test/wp-content/uploads/2020/03/80694475_10220097889178767_6336534537924771840_n-300×229.jpg 300w” sizes=”(max-width: 750px) 100vw, 750px”> There is a data attribute: data-id=”15″ A HTML class: class=”wp-image-15″ A link to the … Read more

Change attached img anchor link to post link

You may try the filter wp_get_attachment_link // definition: apply_filters( ‘wp_get_attachment_link’, “<a href=”” . esc_url( $url ) . “”>$link_text</a>”, $id, $size, $permalink, $icon, $text, $attr ); // this filter provide a max. of 7 arguments, I use 2 in the example add_filter( ‘wp_get_attachment_link’, ‘q363693_update_attachment_link’, 10, 2 ); function q363693_update_attachment_link( $url, $id ) { // some codes … Read more

Frontend AJAX Media Upload returning 404

I can’t find the define of the ajaxurl variable. The 404 is inevitable. Usually, you need to define it in your function or directly in a wp_localize_script action. Dont’t forget to replace the wp_ajax_pn_reg_vendors, to make it work, even the user is not yet connect.

How to echo images Urls from a wordpress post, that are relally in the post

If you want to get the actual images inside the post content, you can match them using a regular expression. To get just the images URLs and dimensions your code can be something like this: if( is_single() ) { global $post; // Match the image URLs inside the post content $pattern = ‘/<img.*src=”([^”]+)”[^>]*>/’; $matches = … Read more

Custom field in media library not saving, selected() function not adding “selected” to select list input type

As per outlined in the comments, by fixing a typo in my save function, and setting the third parameter in get_post_meta() to true, and false in selected() it worked liked a charm. Thanks everyone! Here’s the working code in case anyone is trying to add a select list custom field to their media manager: /* … Read more