Support » Plugins » 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)
  • Which tab are you using – HTML or Visual?

    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.

    Are you adding your shortcode correctly using 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 in case you’re missing an intermediate step.

    Thanks for the links and guide. I will have a look right now.

    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 { ?> 
    	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.


    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.