I'd like this function to only return on certain pages. How might i do that?

// Retreats Accordion
function retreats_accordion() { 

<!-- accordion root --> 
<div id="accordion"> 
        global $post;
        $c = 0;
        $class = '';
        $args = array( 'posts_per_page' => 6, 'post_type'=> 'slide', 'slideshow'=> 'retreats');
        $myposts = get_posts( $args );
        foreach( $myposts as $post ) :  setup_postdata($post);
        if( $c == 6 ) $class .= ' last'; ?>
        <a href="<?php echo get_post_meta($post->ID, "slide_url_value", true); ?>">
            <?php the_post_thumbnail('quickfinder'); ?>
        <div class="slide<?php echo $class;?>" style="width:200px;">    
            <h4><?php the_title(); ?></h4>
            <?php the_content(); ?>
    <?php endforeach; ?>

$(function() {

$("#accordion").tabs("#accordion div", {
    tabs: 'img', 
    effect: 'horizontal'


add_action('nktframework_abovecontent', 'retreats_accordion', 10);

I've tried adding this to the function but it doesn't seem to work.

if( is_page(107) )
  • someone already answered your question here - wordpress.stackexchange.com/questions/6730/… (use output buffering) Commented Jan 11, 2011 at 19:58
  • @Ambitious Amoeba ehm... This seems like absolutely different question to me? That was about shortcode mechanics, this is about conditionals.
    – Rarst
    Commented Jan 11, 2011 at 20:00
  • yes, sorry, I read this too quickly Commented Jan 11, 2011 at 20:14
  • Couldn't you just conditionalise the add_action instead, only attach it when the appropriate page is called, so rather then conditionalising the code in the function, conditionalise the action(it's possible that the is_page call is wrong in the context of that function - outside that may not be the case).
    – t31os
    Commented Jan 11, 2011 at 23:54

2 Answers 2


Your code:

if( is_page(107) )

checks for page and returns nothing on match, effectively it's exactly opposite of what you want. So if you reverse it and put this at start of function:

if( !is_page(107) )

It will do nothing everywhere, but page 107 where it will proceed to run rest of the function.


The above code should work but its kind of a hack, why not create a page template with the complete layout and accordion in it. That way you can select it easily when you create a new page and you dont have to manually edit the page id's every time you need one.

http://codex.wordpress.org/Pages look under Creating Your Own Page Templates

  • Good advice, but it seems some kind of framework is used and those can be very pro-templates and very pro-hooks. My method is hardly a hack, I am used to pro-hook Hybrid framework where working with conditionals is more common than creating templates. So what is best depends on context, there are always many ways to do something in WP.
    – Rarst
    Commented Jan 11, 2011 at 21:42
  • Sorry, i did not mean to call your advice a hack but the original method. Your advice fixed the problem with firefusions code. Just wanted to offer a different perspective.
    – Patriek
    Commented Jan 11, 2011 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.