Checking for ‘gallery’ shortcode using strpos always returns false

You will need global $post to get the $post variable into the scope of that function. function doraemon_scripts() { if( is_single() ) { global $post; if (strpos($post->post_content,'[gallery’) === false){ } else { // wp_enqueue_style( … ); // wp_enqueue_script( … ); } } } add_action( ‘wp_enqueue_scripts’, ‘doraemon_scripts’ ); Using the $post global outside of the Loop … Read more

How to dynamically insert in the image caption?

That markup is created by the caption shortcode. If you look at the the source for that shortcode you will see this: // Allow plugins/themes to override the default caption template. $output = apply_filters(‘img_caption_shortcode’, ”, $attr, $content); if ( $output != ” ) return $output; That means that you can hook a function into img_caption_shortcode … Read more

How can I attach a gallery to a post with a short code?

The gallery is the shortcode. It is not, so far as I know, saved in any other place or in any other way than in that shortcode. You can print/process shortcodes anywhere you want with tricks like this: echo do_shortcode(”); Or this: $gallery_shortcode=”‘; print apply_filters( ‘the_content’, $gallery_shortcode ); Both from the Codex. You can see … Read more

Making a [gallery] in a loop with attachment IDs?

First get all of the feature thumbnail ids, and then populate the gallery. Code – <?php global $wpdb; $featured_ids = $wpdb->get_col(“SELECT meta_value FROM $wpdb->postmeta WHERE meta_key=’_thumbnail_id'”); $featured_ids = array_map(‘intval’, $featured_ids); $featured_ids = array_unique($featured_ids); echo do_shortcode(”); ?>

Where is image gallery information saved?

WordPress doesn’t necessarily save a ton of gallery information in the database. Each time you upload an image ( or any media I believe ) it gets assigned to a built-in post type called simply “attachment” which gives it a unique ID. Whenever you go through the Media Library Popup and create a gallery, WordPress … Read more

WordPress Gallery Thumbnail images look blurry

luckily I found the answer shortly after posting this question. My thumbnail size setting (Settings/Media) was 150 x 150px – cropped. So when I displayed them on my page, desktop size, in a row of 4, the thumbnails were getting stretched to 282 x 282px. I changed it to this new size and used a … Read more

Get gallery images from page ID

You could use the get_post_galleries_images function, which returns an array of all the galleries from whatever post ID you specify. The following is a quick function that will display all the images: function na_get_gallery_image_urls( $post_id, $number = false ) { $post = get_post($post_id); $count = 0; // Make sure the post has a gallery in … Read more

Optimizing wp_get_attachment_image_src

Usually for gallery post types with lots of attachments, you would do it like this: http://codex.wordpress.org/Template_Tags/get_posts#Show_attachments_for_the_current_post Inside a “WordPress Loop”: <?php $args = array( ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { echo apply_filters( ‘the_title’ , $attachment->post_title … Read more