Recently I installed the simple, but beautiful Suffusion theme by Sayontan Sinha. This theme is using the funtions.php file extensively, the same place where my shortcode definitions were stored. Sayontan will probably fix this in the near future by including a custom functions.php file from another location. I also used some PHP code in two sidebar widgets that was executed by the Exec-PHP plugin.
I thought, why not use a plugin to define shortcodes and execute PHP code snippets? I couldn’t find one, so I wrote one myself. You can find it in the WordPress repository as Shortcode Exec PHP.
Example shortcode to print your age:
extract(shortcode_atts(array('birthdate' => 'Jan 1, 1980'), $atts));
return floor((time() - strtotime($birthdate)) / (60 * 60 * 24 * 365.2425));
If you named the shortcode age, you can execute it in pages, posts, comments, widgets and/or RSS feeds like this:
[age birthdate="Mar 20, 2010"]
Please, use the forum for questions, bug reports and feature requests.
If you know a nice shortcode, you can leave it in the forum too.
Install now

Listing posts
If you want to list posts or pages on a post, page or in a widget, you can use the code below.
// Prevent recursion
global $outerPost;
if ($outerPost)
return '';
// Parse parameters
extract(shortcode_atts(array('query' => 'post_type=post'), $atts));
$query = html_entity_decode($query);
// Create new post loop
global $post;
$outerPost = $post;
$my_query = new WP_Query($query);
while ($my_query->have_posts()) {
$my_query->the_post();
setup_postdata($my_query->post);
// Process post
echo '<em>'; the_title(); echo '</em>';
echo '<div style="font-size: xx-small; border: 1px solid;">';
the_content();
echo '<div>';
}
$post = $outerPost;
$outerPost = null;
setup_postdata($post);
Example usage:
[list_posts query="author_name=marcel"]
Look here for possible query parameters.
Be sure the shortcode option ‘Output echoed‘ is checked.
Using forms
Example of form handling:
if (isset($_POST['form_select']))
echo 'You selected ' . $_POST['form_select'] . '<br />';
?>
<form method="post">
<select name="form_select">
<option selected="selected" value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
<input type="submit" value="Submit" />
</form>
Be sure the shortcode option ‘Output echoed‘ is checked.