Top

vtxyzzy on "place the_title inside the_content"

February 14, 2010 by  

Adding a shortcode is one way to to it. Add the code below to your theme’s functions.php. Then, place the shortcode [mm-insert-title] in your post where you want the title to appear. You can use the before and after parameters to put code before and after the title. For example, [mm-insert-title before='<h2>' after='</h2>'] will place the title inside h2 tags.

function mm_insert_title_func($atts) {
   // Insert the post title, with optional before and after strings.
   // [mm-insert-title before='<h3>' after='</h3>']
   global $post;
   extract(shortcode_atts(array('before' => '', 'after' => '' ), $atts));
   $output = "{$before}{$post->post_title}{$after}";

   return $output;
}
add_shortcode('mm-insert-title', 'mm_insert_title_func');
?>
Share

Comments

Facebook comments:

Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!





*
Bottom