How to output PHP in an enclosing shortcode in my theme template?
-
My head is aching…
I have a very nifty plugin called DJ Facebook Share. This plugin allows you to use shortcode to insert a Fb Like button in your post content, as well as a block of content that remains hidden until the Like button is clicked.
Basically the code would look like this inside the content:
[fb-like] [fb-share] Hidden content to be revealed when the Fb Like button above is clicked [/fb-share]
My dilemma is this: I want to put this in the loop of my theme template, since every post needs to have it and it gets freaking tedious entering it all the time. The hidden content has the same wording for each post, except that it a link, and that URL is unique to each post. I’ve created a custom field called “WSO” into which I enter the URL for each post, but I have yet to work out how to get that into the shortcode in PHP format. I’ve tried things like:
<?php if ( get_post_meta($post->ID, 'WSO', true) ) : ?> <?php echo do_shortcode("[fb-like]"); ?> <?php $fbshare = get_post_meta($post->ID,'WSO',true); $content = "THANK YOU, <a href='$fbshare' target='_blank'><strong>CLICK HERE TO VIEW THE WSO</strong></a></br>"; if($fbshare) echo apply_filters( 'the_content', '[fb-share].$content.[/fb-share]' ); ?> <?php endif; ?>
… but to no avail.
Does anyone have an idea for me? Please?
Phil
- The topic ‘How to output PHP in an enclosing shortcode in my theme template?’ is closed to new replies.