Disable WordPress automatic formatting on posts using a shortcode
June 23, 2009
If you often display code snippets on your WordPress blog, you know how bad WordPress automatic formatting can be. With this shortcode you can disable it on a portion of text. Add the following function to your themes functions.php file: function formatter_shortcode($content) { $new_content = ''; $pattern_full = '{(\[raw\].*?\[/raw\])}is’; $pattern_contents = ‘{\[raw\](.*?)\[/raw\]}is’; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if... [Read the full story]
Get the latest x number of wordpress sticky posts
May 16, 2009
Some of you may be wanted to know how to query a specific number of sticky posts for the front page. we’ll assume you already have the loop set up in one of your template files (i.e., home.php, custom-page.php). What we need to do is call up a specific number of stickies. For this example, we’ll load the two latest sticky posts. Just place following php code before your loop: <?php /* Get all sticky posts */ $sticky = get_option( 'sticky_posts' ); /* Sort the stickies with the newest ones at the top */ rsort(... [Read the full story]
preset text in the WordPress post editor
May 16, 2009
There are built-in action and filter hooks that allow us to change things. We’ll be showing you how to use a simple filter to preset text in the WordPress post or page editor. This technique will work with both the visual and HTML editor. We shouldn’t edit core files. Then what should we edit? Only our theme’s functions.php file. or, we could go through the process of making a plugin, but this is pretty simple stuff. Open your functions.php in your favorite text editor and input following PHP code: <?php add_filter(... [Read the full story]
Add private notes to WordPress posts
May 15, 2009
Sometimes, you may need to leave a private note (e.g. only visible to admin) to a post, but there’s no built-in solution in WordPress to do it. Here’s the code you need to add to your functions.php file: add_shortcode( 'note', 'live_note' ); function live_note( $atts, $content = null ) { if ( current_user_can( 'publish_posts' ) ) return '<div class="note">'.$content.'</div>'; return ''; } Once done, simply add the following shortcode in your posts: [note] This is a note that only someone can... [Read the full story]
Return wordpress posts for various date ranges
May 14, 2009
WordPress loop is very powerful, as well as the query_posts() function, which allow you to specify some parameters for the loop to retrieve posts. Though, there’s no built-in function or parameter to return posts for various date ranges. Open your index.php file and find the loop. Just before the loop starts, paste the following code. Of course, don’t forget to change the dates according to your needs. <?php function filter_where($where = '') { //posts in the last 30 days //$where .= " AND post_date > '"... [Read the full story]



















