Posts

get post publish date outside the loop in wordpress

get post publish date outside the loop in wordpress

To get post publish date outside the loop in wordpress use the following code.

$all_posts = get_posts(array('numberposts'=>-1, 'post_status'=> 'publish')); //Get all published posts
foreach ($all_posts as $single_post){
    echo get_the_time('Y-m-d', $single_post->ID); //The date is on Y-m-d format
    echo '<br />' ;
}

Hope this code will help you.
Thanks

google cdn

Load jquery library from google CDN in wordpress

Add this code on wordpress theme functions.php to deregister the urgent jquery and load jquery library from google.

function load_cdn_jquery() {

    // only use this method is we're not in wp-admin
    if (!is_admin()) {

        // deregister the original version of jQuery
        wp_deregister_script('jquery');

        // discover the correct protocol to use
        $protocol='http:';
        if($_SERVER['HTTPS']=='on') {
            $protocol='https:';
        }

        // register the Google CDN version
        wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.5.2');

        // add it back into the queue
        wp_enqueue_script('jquery');
			
		
    }

}

add_action('template_redirect', 'load_cdn_jquery');

10 Useful WordPress functions to reduce your development time

This 10 Useful WordPress functions will certainly reduce your WordPress development time.I found this functions when i do some research for my projects. So i think i better share this with you.

1.Custom Excerpt Length

By default, excerpt length is set to 55 words. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:

function custom_excerpt_length( $length ) {
	return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Find more here.
Read more

8 useful PHP code snippets for developers

Today, i want to share you some useful PHP code snippets which may reduce your development time.

1.Send HTML Mail

<?php
$to = "info@yoursite.com";
$subject = "This is my test html email send using php mail function";
$body    = "Body of your message here you can use HTML too. <br /> <h1> Header </h1> ;";
$headers = "From: User \r\n";
$headers.= "Reply-To: info@yoursite.com\r\n";
$headers.= "Return-Path: info@yoursite.com\r\n";
$headers.= <"X-Mailer: PHP5\n";
$headers.= 'MIME-Version: 1.0'."\n";
$headers.= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
mail($to,$subject,$body,$headers);
?>

Read more