how to write short code in word press

According to the WordPress documentation, “a minimal example of the PHP code required to create shortcode with attributes” is // [bartag foo=”foo-value”] function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); return “foo = {$foo}”; } add_shortcode( ‘bartag’, ‘bartag_func’ ); You can find more detailed … Read more

Shortcodes don’t work online

First, change this: include TEMPLATEPATH . ‘/extras/shortcodes.php’; …to this: include ( TEMPLATEPATH . ‘/extras/shortcodes.php’ ); Second, change TEMPLATEPATH to get_template_directory(): include ( get_template_directory() . ‘/extras/shortcodes.php’ ); (The TEMPLATEPATH and STYLESHEETPATH globals are going away eventually.) Third, make sure you namespace your function names properly. Function names “alertBox()” and “infoBox()” are far too generic. Beyond that, … Read more

Substituting value via shortcode

If you put variables inside a string, you have to use ” double quotes. So: // This: $qstr=” SELECT * … ORDER BY $wpdb->posts.post_date DESC “; // becomes… $qstr = ” SELECT * … ORDER BY $wpdb->posts.post_date DESC “;

Replacing custom field with shortcode

A shortcode like this [thumbnail height=100 width=100]http://urltoimage.com/image.jpg[/thumbnail] Would need this type of setup function content_insert_thumbnail($atts, $content = null){ global $post; extract($atts); $thumbnail = get_the_post_thumbnail($post->ID, array($height, $width)); $content .= $thumbnail; //Places the thumbnail after the content return $content; //Never echo a value from a shortcode function. } add_shortcode(‘thumbnail’, ‘content_insert_thumbnail’); To call this in your theme to … Read more

Execute Shortcodes when submitting post

That’s not how shortcodes work. Shortcodes are meant to be interpreted whenever the page is rendered – they’re used when WordPress filters the page/post content. What you’re looking for is a content template. A tag the user can add to the page that will be converted into something else when the post is saved, like … Read more

post content and shortcode content displaying out of order

Replacing echo with return doesn’t work because your function is immediately terminated once it hits a return. See PHP docs for return. It would be helpful to see your actual code, but the general concept within your shortcode function would be: $output=””; // initialize output while( $your_shortcode_query->have_posts() ): $your_shortcode_query->the_post(); $foo = get_the_title(); $bar = get_permalink(); … Read more

Allow tags between shortcode in comments

You want to allow folks to post code in their comments, like on here were we can just do <p>something</p> without having to worry about doing any &gt; or &lt; stuff? I think you’ll still want those special html characters converted to their respective entities, but you need to stay under the radar to avoid … Read more