Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im trying to echo the content from inside shortcodes into a conditional. I have two shortcodes like this:

function fb_fans( $atts, $content = null ) { return $content; }
add_shortcode( 'fans', 'fb_fans' );

function fb_nonfans( $atts, $content = null ) { return $content; }
add_shortcode( 'nonfans', 'fb_nonfans' );

then inside the loop I want echo content that the user puts inside...
[fans] echo this content [/fans] and also
[nonfans] else echo this [/nonfans]

heres what I have that obviously doesnt work

if ($like_status) { echo $fb_fans; } else {  echo $fb_nonfans; } 

anyone know how to write this correctly??? Thanks!

share|improve this question

2 Answers 2

Use the actual function if you want to programatically call the shortcode.

echo fb_fans($atts, $content);

UPDATE:

Well, I think you need to go back to learning how shortcodes work. You simply need to use the_content() to display shortcodes properly.

Within your content area, you the user would type:

[fans]FOOBAR[/fans]

This would output FOOBAR inside of the content. A shortcode is basically a way to use PHP functions within the content area safely.

share|improve this answer
    
unfortunately its coming up blank. scratching my head because two of you had the same answer. Maybe i need to add something to my loop to get content? heres the whole loop....... if (have_posts()) : while (have_posts()) : the_post(); if ($like_status) { echo fb_fans($atts, $content); } else { echo fb_nonfans($atts, $content); } endwhile; endif; –  user12571 Jan 30 '12 at 2:22
    
You have to declare the variables $atts and $content to contain some sort of data. –  Brian Fegter Jan 30 '12 at 3:02
    
any idea of how to do that, when I want to only echo what the user puts inside of each shortcode? –  user12571 Jan 30 '12 at 3:39
    
youre definitely right about learning shortcodes. this is a very simple shortcode. instead of return $content i tried return do_shortcode($content); I think it made a difference. Where Im getting tripped us is how to write a conditional, where one shortcode content is the if, and other is the else. –  user12571 Jan 30 '12 at 23:06
    
Why not use a FB plugin to do all of this? There are plenty out there. :) –  Brian Fegter Jan 31 '12 at 2:25

Here is your answer :)

 echo fb_fans($atts, $content);
share|improve this answer
    
That's a copy of my answer. –  Brian Fegter Jan 30 '12 at 16:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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