Using Cron to schedule events in WordPress

August 12, 2009

WordPress can schedule events. but how you create an event that will be executed once hourly, or daily, etc? Just copy following code to your functions.php file: if (!wp_next_scheduled('live_task_hook')) { wp_schedule_event( time(), 'hourly', 'live_task_hook' ); } add_action( 'live_task_hook', 'live_task_function' ); function live_task_function() { wp_mail('', 'Automatic email', 'Hello, this is an automatically scheduled email from Live Experience.'); } On line 1, we created an event, after verifying... [Read the full story]

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 1 image $iNumberOfImages... [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]

Get tags based on the wordpress category

June 27, 2009

Althought WordPress allow you to do lots of things by default, but how to retrieve tags based on the category? Just paste following code wherever you need to display the list of tags that are specific to a particular category. Note: You can replace the category name on line two.   <?php query_posts('category_name=wordpress'); if (have_posts()) : while (have_posts()) : the_post();         $posttags = get_the_tags(); if ($posttags) { foreach($posttags as $tag) { $all_tags_arr[] = $tag -> name; //USING... [Read the full story]