Title: Gallery shortcode does not recognize post content
Last modified: August 19, 2016

---

# Gallery shortcode does not recognize post content

 *  [banago](https://wordpress.org/support/users/banago/)
 * (@banago)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/)
 * Hi Guys,
 * I’m developing a gallery for WordPress. The coding went well and the gallery 
   shows up now by using a shortcode. I have only one problem. When I put the shortcode
   into the middle of the post/page content, it ignores it and shows up at the top
   of the content. What could cause this?
 * Thanks guys!

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1273958)
 * Which tab are you using – HTML or Visual?
 *  Thread Starter [banago](https://wordpress.org/support/users/banago/)
 * (@banago)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274038)
 * I’m using Visual. However, it’s the same. I tried the default shortcode [gallery]
   and it showed up where I put it i.e. in the middle of content. Whereas my shortcode
   makes the gallery show over the content.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274072)
 * Are you adding your shortcode correctly using [add_shortcode](http://codex.wordpress.org/Function_Reference/add_shortcode)?
   If you have a look at wp-includes/media.php, you can get an idea of how the default
   gallery shortcode is added. Also checkout the [Shortcode API](http://codex.wordpress.org/Shortcode_API)
   in case you’re missing an intermediate step.
 *  Thread Starter [banago](https://wordpress.org/support/users/banago/)
 * (@banago)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274111)
 * Thanks for the links and guide. I will have a look right now.
 *  Thread Starter [banago](https://wordpress.org/support/users/banago/)
 * (@banago)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274127)
 * Here is my (cleaned up from html) code:
 *     ```
       <?php function wp_gallery($width = '', $height = '', $resize = 'no', $echo = true) {
       	global $post, $id;
   
       	$galleria_options = get_option('galleria_options');
       	$width = intval($galleria_options['width']);
       	$height = intval($galleria_options['height']);
       	$resize = intval($galleria_options['resize']);	
   
       	$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . get_the_id() );
       	if ( empty($images) ) { echo "There are no images attached to this post."; }
       	else { ?> 
   
       	<?php
       	foreach( $images as $imageID => $imagePost ){
          $src = wp_get_attachment_image_src($imageID, 'medium', true);
       	$img = $src[0];
       		if ( $resize == 1 ) {
         		echo '<li class="active"><img src="' . WP_PLUGIN_URL . '/wp-galleria/img/thumb.php?src='. $img .'&h='. $height .'&w='. $width .'&zc=1" alt="'. get_the_title($imagePost) .'" title="'. get_the_title($imagePost) .'" width="'. $width .'" /></li>';
         		} else {
         		echo '<li class="active"><img src="'. $img.'" alt="'. get_the_title($imagePost) .'" title="'. get_the_title($imagePost) .'" /></li>';
         		}
         	}
       	?>
       <?php } }
       ### Shortcode
       add_shortcode("gallery", "wp_gallery");
       ?>
       ```
   
 * What can be wrong? Thanks very very much.
 *  Thread Starter [banago](https://wordpress.org/support/users/banago/)
 * (@banago)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274149)
 * help!
 *  [normtb2](https://wordpress.org/support/users/normtb2/)
 * (@normtb2)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274307)
 * When you echo the html it shows up at the top of the post. Store all of the output
   html into a string and return that string.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Gallery shortcode does not recognize post content’ is closed to new replies.

## Tags

 * [gallery](https://wordpress.org/support/topic-tag/gallery/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 7 replies
 * 3 participants
 * Last reply from: [normtb2](https://wordpress.org/support/users/normtb2/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/gallery-shortcode-does-not-recognize-post-content/#post-1274307)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
