Disable wordpress posts auto saving

August 12, 2009

WordPress have a very useful function that autosaves your posts while you’re typing them in the dashboard. Though, if for some reason you’d like to disable this function, it is very easy to do. To disable WordPress autosaving function, simply open your functions.php file and paste the following code: function disableAutoSave(){ wp_deregister_script('autosave'); } add_action( 'wp_print_scripts', 'disableAutoSave' ); Once you saved the file, WordPress will never autosave a post. To enable autosaving again,... [Read the full story]

Detect if wordpress post has at least one image

July 25, 2009

On a WordPress, it can be really handy to be able to know if a post has at least one image or not, for example for grabbing the first image and display it. To achieve this, simply paste the code below within the loop, on your index.php, search.php or archive.php file. <?php $content = $post->post_content; $searchimages = '~<img [^>]* />~’; /*Run preg_match_all to grab all the images and save the results in $images*/ preg_match_all( $searchimages, $content, $images ); // Check to see if we have at least... [Read the full story]

Showing the post password form for excerpts in WordPress

June 27, 2009

Many WordPress themes show excerpts on the front page and other archive-type views. When viewing a password-protected post, this message is displayed: There is no excerpt because this is a protected post. While this is fine for many scenarios, it may not be the most helpful piece of text for the average Internet user. Instead of showing the message, we’ll replace it with a password form. Replacing the no excerpt text with a password form WordPress comes packaged with a neat function called get_the_password_form() that... [Read the full story]

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]

Page 1 of 1312345»...Last »