logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$100
Problems showing shortcode outside the_content!

I am using the plugin Galleria WP to show an image slider in posts but due to a redesign I now need to place the image slider outside the_content snippet.

The problem is that when I use this code it seems to pull WordPress' own shortcode [gallery] instead of showing the image slider (as it does when the shortcode only is place inside the_content):

<?php echo do_shortcode('[galleria thumbnail="bottom-scroll"]'); ?>


I have tried with applying filters and tried to find an answer in forum threads etc. No luck. I run the site locally so you'll need to check out the plugin Galleria WP and run it on your own demo site.

This question has been answered.

LeTune | 05/30/11 at 9:21am Edit


(3) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/30/11
    9:26am
    Dan | gteh says:

    What version of wordpress are you using?

    Galleria WP http://wordpress.org/extend/plugins/galleria-wp/ has not been developed since 2008 and is compatible up to Wordpress 2.5 only

    • 05/30/11 9:40am

      LeTune says:

      But the shortcode works when placed in the posts and rendered through the_content() snippet. So the plugin works, just not outside the_content

  • avatar
    Last edited:
    05/30/11
    9:28am
    Erez S says:

    Well, you can save the shortcode value inside the loop and then to print it outside the loop

    • 05/30/11 9:33am

      Erez S says:

      Something like this:


      <?php $tempval = do_shortcode('[galleria thumbnail="bottom-scroll"]'); ?>

      Inside the loop and then outside the loop simply do:

      <?php echo $tempval; ?>

    • 05/30/11 9:35am

      Erez S says:

      Or like this(inside the loop):

      <?php
      ob_start();

      echo do_shortcode('[galleria thumbnail="bottom-scroll"]');

      $tempval = ob_get_contents();

      ob_end_clean();
      ?>


      And then this is outside:
      <?php echo $tempval; ?>


      Hope it works

    • 05/30/11 9:39am

      LeTune says:

      Hi Erik, as the shortcode works when placed in the_content, it is technically already inside the loop, so that can't be the problem. Also when the shortcode is placed in the_excerpt or custom field, the same problem

    • 05/30/11 9:45am

      Erez S says:

      Shortcodes souldn't work on custom fields and excerpt, however if you want it work you have to add this filter:

      <?php add_filter( 'the_excerpt', 'do_shortcode', 11); ?>

      However, I think you should try what I'v said above, since I guess that the function which activated when you using the shortcode should be inside the loop, so if you'll save the shortcode value when it's inside the loop you'll be able to print it outside the loop

    • 05/30/11 9:47am

      Erez S says:

      Anyway, can you send me the code of the page that you using this shortcode in?

    • 05/30/11 9:51am

      LeTune says:

      Hi Erez,
      I get your argument and I applied your code suggestion without any success. The question is: why does the shortcode work inside the_content and not outside?

    • 05/30/11 9:57am

      LeTune says:

      Here's the code:


      <?php get_header(); ?>


      <?php while (have_posts()) : the_post(); ?>
      <?php
      if(in_category('Arkitektur')) echo '<div class="top-text-arkitektur">';
      elseif(in_category('Architecture')) echo '<div class="top-text-arkitektur">';
      elseif(in_category('Design')) echo '<div class="top-text-design">';
      elseif(in_category('Design @en')) echo '<div class="top-text-design">';
      elseif(in_category('Utveckling')) echo '<div class="top-text-utveckling">';
      elseif(in_category('Development')) echo '<div class="top-text-utveckling">';
      elseif(in_category('Koncept')) echo '<div class="top-text-koncept">';
      elseif(in_category('Concept')) echo '<div class="top-text-koncept">';
      elseif(in_category('Visualisering')) echo '<div class="top-text-visualisering">';
      elseif(in_category('Visualization')) echo '<div class="top-text-visualisering">';
      ?>

      <h1><?php the_title(); ?></h1>
      <p><?php the_excerpt(); ?></p>

      </div> <!-- end top-text -->
      <div class="nav-menu">
      <?php wp_list_categories('orderby=name&exclude=1,5,3,18,20,19,22,28, 29,27&title_li='); ?>
      </div> <!-- end nav-menu -->
      <div class="nav-menu">
      <?php wp_list_pages('orderby=name&exclude=1,5, 194, 198, 196, 200&title_li='); ?>
      </div> <!-- end nav-menu -->
      <div class="nav-menu1">



      </div> <!-- end nav-menu1 -->
      </div> <!-- end head-wrap -->
      <div class="main-title"><h3><?php the_breadcrumb(); ?></h3></div>
      <div id="main">



      <?php echo do_shortcode('[galleria thumbnail="bottom-scroll"]'); ?>


      <div class="main-bottom"></div>
      <div class="main-wrap">
      <div class="post-left">
      <?php the_content(); ?>
      </div>
      <div class="sidebar">
      </div>
      </div>



      <?php endwhile;?>

      </div>
      <?php get_footer(); ?>


      And here's the output as attached jpg

      Attached Image

    • 05/30/11 9:57am

      Erez S says:

      I guuss it's because the plugin using the $post variable, but you are using it outside the loop so the plugin can't recive the right images.
      So what I suggest is to add the loop again where you need to display the shortcode, or you can give me the your code so I'll try to find out what's the problem

    • 05/30/11 10:01am

      Erez S says:

      <?php get_header(); ?>
      <?php while (have_posts()) : the_post(); ?>
      <?php
      if(in_category('Arkitektur')) echo '<div class="top-text-arkitektur">';
      elseif(in_category('Architecture')) echo '<div class="top-text-arkitektur">';
      elseif(in_category('Design')) echo '<div class="top-text-design">';
      elseif(in_category('Design @en')) echo '<div class="top-text-design">';
      elseif(in_category('Utveckling')) echo '<div class="top-text-utveckling">';
      elseif(in_category('Development')) echo '<div class="top-text-utveckling">';
      elseif(in_category('Koncept')) echo '<div class="top-text-koncept">';
      elseif(in_category('Concept')) echo '<div class="top-text-koncept">';
      elseif(in_category('Visualisering')) echo '<div class="top-text-visualisering">';
      elseif(in_category('Visualization')) echo '<div class="top-text-visualisering">';
      ?>
      <h1><?php the_title(); ?></h1>
      <p><?php the_excerpt(); ?></p>
      </div> <!-- end top-text -->
      <div class="nav-menu">
      <?php wp_list_categories('orderby=name&exclude=1,5,3,18,20,19,22,28, 29,27&title_li='); ?>
      </div> <!-- end nav-menu -->
      <div class="nav-menu">
      <?php wp_list_pages('orderby=name&exclude=1,5, 194, 198, 196, 200&title_li='); ?>
      </div> <!-- end nav-menu -->
      <div class="nav-menu1">
      </div> <!-- end nav-menu1 -->
      </div> <!-- end head-wrap -->
      <div class="main-title"><h3><?php the_breadcrumb(); ?></h3></div>
      <div id="main">
      <?php echo apply_filters( 'the_content', 'galleria thumbnail="bottom-scroll"]'); ?>
      <div class="main-bottom"></div>
      <div class="main-wrap">
      <div class="post-left">
      <?php the_content(); ?>
      </div>
      <div class="sidebar">
      </div>
      </div>
      <?php endwhile;?>
      </div>
      <?php get_footer(); ?>

      This is Adam's solution...

  • avatar
    Last edited:
    05/30/11
    9:39am
    AdamGold says:

    Try to run:

    <?php apply_filters( 'the_content', '[galleria]'); ?>

    Previous versions of this answer: 05/30/11 at 9:39am

    • 05/30/11 9:43am

      LeTune says:

      Hi Adam, then nothing shows, not even the result of [gallery] as it did when I placed the shortcode in a echo do_shortcode.

    • 05/30/11 9:56am

      AdamGold says:

      Try

      <?php echo apply_filters( 'the_content', '[galleria]'); ?>

    • 05/30/11 9:59am

      LeTune says:

      freaaakkinggg genius!!! it worked. how come the "echo" made the difference?

    • 05/30/11 10:01am

      AdamGold says:

      Awesome! :)
      The echo is just printing the output, before it was just running in background without being outputted :)

This question has expired.



Lawrence Krubner had additional discourse to offer.

Erez S, LeTune voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.