Check if post has gallery images/media

No Need for SQL queries in the template. function wpse_72594_get_attachments( $id, $mime=”” ) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => $mime, ‘post_parent’ => $id ); $attachments = get_posts($args); if ($attachments) return $attachments; return false; } Then call the function like this (300 is the post ID): wpse_72594_get_attachments(300), grabs all attachments wpse_72594_get_attachments(300, ‘image’ ), … Read more

How to get gallery id inserted to a post?

In single.php i put this code, from this link (thank you Wyck) https://stackoverflow.com/questions/14277794/wordpress-3-5-own-gallery-with-included-images-doesnt-work preg_match(‘/\/’, $post_content, $ids); $array_id = explode(“,”, $ids[1]); print_r($array_id); Now I can use gallery shortcode

Get meta data from image

Image data is stored as if it were a post, or a CPT, so you can treat it like one. $album_id = get_the_id(); $img = new WP_Query(array(‘p’=>$album_id,’post_type’=>’attachment’)); var_dump($img->posts[0]->post_content); Or, a little more complicated,… $album_id = get_the_id(); $img = new WP_Query(array(‘p’=>$album_id,’post_type’=>’attachment’)); if (!empty($img->posts[0])) { var_dump($img->posts[0]->post_content); } get_the_ID will return the ID of the current post so … Read more

Gallery plugin forces itself above text

Your shortcode function callback must return the output, like this: function gamma_gallery( $attr ) { $html=””; // your stuff, where all the output is assigned to the $html variable return $html; } or you could try the output buffering: function gamma_gallery( $attr ) { $html=””; ob_start(); // your stuff $html = ob_get_contents(); ob_end_clean(); return $html; … Read more

How to hide first gallery for every post?

You could use preg_replace() but I think it’s much easier to overwrite the $output via the post_gallery filter and then remove the filter after the first run: /** * Remove the output of the first gallery * * @param string $output * @param array $attr * @return string $output */ function wpse125903_remove_the_first_gallery( $output, $attr ) … Read more

How to change the target size of images clicked on in WordPress standard gallery

I came across a solution for your functions.php from the following site that looks like it will do the trick. More detail on the implementation here: http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/ Snippet below: function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) { // Only do this if we’re getting the file URL if (! $permalink) { // This returns an … Read more

ACF gallery hook?

You can use the same filter, just replace the type: add_filter(‘acf/update_value/type=gallery’, ‘my_acf_update_value’, 10, 3); All fields extend the same base class, so they also share the same basic filters.

Set default number of columns in gallery

You can override many of the Gallery Settings using the media_view_settings filter: /** /* Gallery Default Settings /* @param Array $settings /* @return Array $settings */ function theme_gallery_defaults( $settings ) { $settings[‘galleryDefaults’][‘columns’] = 5; return $settings; } add_filter( ‘media_view_settings’, ‘theme_gallery_defaults’ ); To change more settings, the easiest way is to use Developer Tools to inspect … Read more

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