How To Display A Thumbnail Of Any Website
Using the following snippet, you will be able to display a thumbnail of any website.
1 2 3 4 5 6 7 8 9 10 11 12 |
function wpr_snap($atts, $content = null) { extract(shortcode_atts(array( "snap" => 'http://s.wordpress.com/mshots/v1/', "url" => 'http://www.catswhocode.com', "alt" => 'My image', "w" => '400', // width "h" => '300' // height ), $atts)); $img = '<img src="' . $snap . '' . urlencode($url) . '?w=' . $w . '&h=' . $h . '" alt="' . $alt . '"/>'; return $img; } add_shortcode("snap", "wpr_snap"); |
Once done, you can use the snap shortcode:
1 |
[snap url="http://www.codeandme.net" alt="My description" w="400" h="300"] |
Snippet Source/Credit: Greekeries.fr
How To Automatically notify your members on new posts
Using the following snippet, you will be able to automatically notify your members on new posts.
1 2 3 4 5 6 7 8 |
function email_members($post_ID) { global $wpdb; $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $users = implode(",", $usersarray); mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com'); return $post_ID; } add_action('publish_post', 'email_members'); |
Snippet Source/Credit: WordPress Codex
How To Display A Thumbnail From A YouTube Video Using A shortcode
Using the following snippet, you will be able to display a thumbnail from a YouTube video using a shortcode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* Shortcode to display youtube thumbnail on your wordpress blog. Usage: [youtube_thumb id="VIDEO_ID" img="0" align="left"] VIDEO_ID= Youtube video id img=0,1,2 or 3 align= left,right,center */ function wp_youtube_video_thumbnail($atts) { extract(shortcode_atts(array( 'id' => '', 'img' => '0', 'align'=>'left' ), $atts)); $align_class='align'.$align; return '<img src="<a href="http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg"" rel="nofollow">http://img.youtube.com/vi/'.$id.'/'.$img.'.jpg"</a>; alt="" class="'.$align_class.'" />'; } add_shortcode('youtube_thumb', 'wp_youtube_video_thumbnail'); Once done, all you have to do is to use the shortcode below: [youtube_thumb id="rNWeBVBqo2c" img="0" align="center"] |
Snippet Source/Credit: Gunay
How To Automatically Add Post Name To The Body Class
Add the following snippet in your theme’s functions.php file, you will be able to automatically add post name to the body class.
1 2 3 4 5 6 7 8 9 |
function wpprogrammer_post_name_in_body_class( $classes ){ if( is_singular() ) { global $post; array_push( $classes, "{$post->post_type}-{$post->post_name}" ); } return $classes; } add_filter( 'body_class', 'wpprogrammer_post_name_in_body_class' ); |
Snippet source/Credit: WPProgrammer.com
How To Add An Extra Contact Methods To User Profiles
Using the following snippet, you will be able to add an extra contact methods to user profiles.
1 2 3 4 5 6 |
add_filter('user_contactmethods', 'my_user_contactmethods'); function my_user_contactmethods($user_contactmethods){ $user_contactmethods['twitter'] = 'Twitter Username'; $user_contactmethods['facebook'] = 'Facebook Username'; return $user_contactmethods; } |
Snippet Source/Credit: TutsPlus
How To Automatically Prefetch Next Pages On Your WordPress Blog
Using the following snippet will let you automatically prefetch next pages on your WordPress blog. All you have to do is to simply paste the snippet in your theme’s header.php file and you are done.
1 2 3 4 |
<?php if (is_archive() && ($paged > 1) && ($paged < $wp_query->max_num_pages)) { ?> <link rel="prefetch" href="<?php echo get_next_posts_page_link(); ?>"> <link rel="prerender" href="<?php echo get_next_posts_page_link(); ?>"> <?php } ?> |
Snippet Source/Credit: Bernd