WordPress.org

Ready to get started?Download WordPress

Forums

Gallery shortcode does not recognize post content (8 posts)

  1. Baki Goxhaj
    Member
    Posted 4 years ago #

    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!

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Which tab are you using - HTML or Visual?

  3. Baki Goxhaj
    Member
    Posted 4 years ago #

    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.

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    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.

  5. Baki Goxhaj
    Member
    Posted 4 years ago #

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

  6. Baki Goxhaj
    Member
    Posted 4 years ago #

    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.

  7. Baki Goxhaj
    Member
    Posted 4 years ago #

    help!

  8. normtb2
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic