How to create a shortcode to let the user add the ID of a YouTube video?

add_shortcode(‘youtube’, ‘youtube_shortcode’); function youtube_shortcode($atts){ if(!isset($atts[0])) return; $id = strip_tags($atts[0]); ob_start(); ?> <div><a class=”fancybox” href=”#video_<?php echo $id; ?>”> <img src=”http://img.youtube.com/vi/<?php echo $id; ?>/0.jpg” alt=”Welcome To High Output” width=”220px” height=”120px” /></a></div> <div id=”video_<?php echo $id; ?>” style=”display: none;”> <iframe title=”YouTube video player” class=”youtube-player” type=”text/html” width=”480″ height=”390″ src=”http://www.youtube.com/embed/<?php echo $id; ?>” frameborder=”0″ allowFullScreen></iframe></div> <?php return ob_get_clean(); } use … Read more

Output loop to function return?

First, need to lose query_posts() – it should never be used for secondary loops. Try something like this: $posts = get_posts( array( ‘cat’ => $category->term_id, ‘numberposts’ => 3, )); foreach( $posts as $post ) { $listing_code .= get_permalink( $post->ID ); //or whatever }

WordPress global variables?

Meta data is save in postmeta table and to get them you can use get_post_meta($post_id,’meta_key_name’,true); so in your shortcode function globilaize $post object and get you value like that if($something == “value”) { global $post; $one = get_post_meta($post->ID,’value_name’true); $two = get_post_meta($post->ID,’value2_name’true); }

Help with WordPress function inside a shortcode

It looks like you’re using a php tag within a php tag. I’d try something more like this… <?php echo do_shortcode(‘[button type=”square” color=”black” size=”small”] Posted by ‘.get_the_author().’ [/button]’); ?> or something like this… <?php $shortcode=”[button type=”square” color=”black” size=”small”] Posted by “.get_the_author().’ [/button]’; echo “do_shortcode(‘$shortcode’)”; ?>

Populating shortcode values dynamically in theme template

You should be able to use do_shortcode(), with a few modifications: <?php echo do_shortcode( ‘[sws_toggle3 title=”‘ . get_the_title() . ‘”]’ . get_the_content() . ‘[/sws_toggle3]’ ); ?> EDIT If you need to maintain the formatting of the_content(), simply pass get_the_content() through the appropriate filter: <?php $content = get_the_content(); $content = apply_filters( ‘the_content’, $content ); echo do_shortcode( … Read more