Title: creating a my_recent_posts shortcode
Last modified: August 20, 2016

---

# creating a my_recent_posts shortcode

 *  [danmcclure](https://wordpress.org/support/users/danmcclure/)
 * (@danmcclure)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/)
 * Hey guys,
 * for some reason I can’t get sanitize title to work. I’m using the following code
   to create a shortcode in Shortcode Exec PHP Administration. When I echo the_title()
   it shows “Test Post”. When I echo sanitize_title( the_title() )it shows the same
   thing “Test Post”. If I echo sanitize_title( ‘Test Post’ ) it shows test-post.
   As far as I understand it its ok to pass the_title() to sanitize_title() but 
   for whatever reason it doesn’t seem to be working. Any help?
 * *also am I in the right place here? I’ve only ever posted to specific plugin 
   support*
 * Thanks,
 * Dan
 * code:
 *     ```
       extract(shortcode_atts(array('arg' => 'default'), $atts));
       $post_author = do_shortcode( '[post_author]' );
       $user = get_user_by('login', $post_author);
       query_posts('author='.$user->ID.'&order=ASC');
       while ( have_posts() ) : the_post();
       	echo '
       <li>';
       	echo sanitize_title( the_title());
       	echo '<a href="http://www.businessnetworkingorangecounty.com/';
       	sanitize_title( the_title() );
       	echo '">';
       	the_title();
       	echo '';
       	echo '</li>
       ';
       endwhile;
       ```
   
 * _[Moderator Note: Please post code or markup snippets between backticks or use
   the code button. As it stands, your code may now have been permanently damaged/
   corrupted by the forum’s parser.]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [danmcclure](https://wordpress.org/support/users/danmcclure/)
 * (@danmcclure)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/#post-3043162)
 * Taking it a little further. The problem seems to be with strip_tags(). It either
   returns “” or returns the same thing that was input. Any thoughts?
 * Dan
 *  Thread Starter [danmcclure](https://wordpress.org/support/users/danmcclure/)
 * (@danmcclure)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/#post-3043163)
 * Ok so:
 * `echo str_replace(' ', '-', strtolower(the_title()));`
 * shows Test Post. I am really lost on this one…
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/#post-3043198)
 * [http://codex.wordpress.org/Function_Reference/the_title](http://codex.wordpress.org/Function_Reference/the_title)
 * `the_title()` will _echo/print _the title;
 * – to _return _the title, use `get_the_title()` or `the_title('','',false)`
 *  Thread Starter [danmcclure](https://wordpress.org/support/users/danmcclure/)
 * (@danmcclure)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/#post-3043230)
 * Ahhhhhhhhhhhhhhhhhhhhh. Thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘creating a my_recent_posts shortcode’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [danmcclure](https://wordpress.org/support/users/danmcclure/)
 * Last activity: [13 years, 8 months ago](https://wordpress.org/support/topic/creating-a-my_recent_posts-shortcode/#post-3043230)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
