The following lines of code will let you check PHP version of your WordPress website.
1 2 3 4 5 | <?php if ( version_compare(PHP_VERSION, '5.2.4', '<') ) { wp_die('PHP 5.2.4 is required.'); }; ?> |
Snippet Source/Credit: PHP.net
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet
The following lines of code will let you check PHP version of your WordPress website.
1 2 3 4 5 | <?php if ( version_compare(PHP_VERSION, '5.2.4', '<') ) { wp_die('PHP 5.2.4 is required.'); }; ?> |
Snippet Source/Credit: PHP.net
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Adding the following snippet to your theme’s functions.php file, you will be able to set a maximum word count on post titles.
1 2 3 4 5 6 7 | function maxWord($title){ global $post; $title = $post->post_title; if (str_word_count($title) >= 10 ) //set this to the maximum number of words wp_die( __('Error: your post title is over the maximum word count.') ); } add_action('publish_post', 'maxWord'); |
Snippet Source/Credit: Pippin
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Use the snippet below and you are able to change the font as per your wish.
1 2 3 4 5 | add_action( 'admin_head-post.php', 'devpress_fix_html_editor_font' ); add_action( 'admin_head-post-new.php', 'devpress_fix_html_editor_font' ); function devpress_fix_html_editor_font() { ?> <style type="text/css">#editorcontainer #content, #wp_mce_fullscreen { font-family: Georgia, "Times New Roman", "Bitstream Charter", Times, serif; }</style> <?php } |
Snippet Source/Credit: DevPress
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to add a logo to a template.
1 | <img src="<?php echo get_stylesheet_directory_uri()?>/images/logo.png" alt="My Logo"> |
Snippet Source/Credit: WPSnipp
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet
Adding the following snippet will let you delete post from front end in WordPress.
1 2 3 4 5 6 7 8 | <?php $url = get_bloginfo('url'); if (current_user_can('edit_post', $post->ID)){ echo '<a class="delete-post" href="'; echo wp_nonce_url("$url/wp-admin/post.php?action=trash&post=$id", 'delete-post_' . $post->ID); echo '">Delete post</a>'; } ?> |
Snippet Source/Credit: WordPress.org
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet
The following snippet will let you detect users from Twitter in WordPress.
1 2 3 4 5 | <?php if (strpos($_SERVER[HTTP_REFERER], "twitter.com") == true) { echo "Hello Twitter User!"; } ?> |
Snippet Source/Credit: WP-Snippets.com
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
To achieve the same, simply find a file name search.php and locate the following:
1 | <h2 class="pagetitle">Search Results</h2> |
Now, simply replace it with to:
1 2 3 4 5 6 7 8 9 | <h2 class="pagetitle">Search Results for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2> |
Snippet Source/Credit: ProBlogDesign
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Simply copy the snippet and paste it to your theme’s functions.php file and you will be able to redirect to a custom page after registration.
1 2 3 4 | function __my_registration_redirect(){ return home_url( '/my-page' ); } add_filter( 'registration_redirect', '__my_registration_redirect' ); |
Snippet Source/Credit: TheDeadMedic
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the snippet below in your theme’s functions.php file will let you display thumbnail of a YouTube video.
Shortcode to display youtube thumbnail on your wordpress blog. Usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [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:
1 | [youtube_thumb id="rNWeBVBqo2c" img="0" align="center"] |
Snippet Source/Credit: Gunay
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to embed a page into another page in your WordPress blog.
1 2 3 4 | <?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?> <h3><?php the_title(); ?></h3> <?php the_content(); ?> <?php endwhile; ?> |
Snippet Source/Credit: CSS Tricks