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.
AdamGold answers:
Try to run:
<?php apply_filters( 'the_content', '[galleria]'); ?>
LeTune comments:
Hi Adam, then nothing shows, not even the result of [gallery] as it did when I placed the shortcode in a echo do_shortcode.
AdamGold comments:
Try
<?php echo apply_filters( 'the_content', '[galleria]'); ?>
LeTune comments:
freaaakkinggg genius!!! it worked. how come the "echo" made the difference?
AdamGold comments:
Awesome! :)
The echo is just printing the output, before it was just running in background without being outputted :)
Dan | gteh answers:
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
LeTune comments:
But the shortcode works when placed in the posts and rendered through the_content() snippet. So the plugin works, just not outside the_content
Erez S answers:
Well, you can save the shortcode value inside the loop and then to print it outside the loop
Erez S comments:
Something like this:
<?php $tempval = do_shortcode('[galleria thumbnail="bottom-scroll"]'); ?>
Inside the loop and then outside the loop simply do:
<?php echo $tempval; ?>
Erez S comments:
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
LeTune comments:
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
Erez S comments:
Shortcodes <strong>souldn't</strong> 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
Erez S comments:
Anyway, can you send me the code of the page that you using this shortcode in?
LeTune comments:
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?
LeTune comments:
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