How To Protect Your Blog Against Image Hotlinking
Using the following snippet you will be able to protect your blog against image hotlinking.
1 2 3 4 5 6 |
RewriteEngine On #Replace ?mysite\.com/ with your blog url RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC] RewriteCond %{HTTP_REFERER} !^$ #Replace /images/nohotlink.jpg with your "don't hotlink" image url RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L] |
Snippet Source/Credit: WPRecipies
How To Search Within Post Type Only
If you want to force the search engine to search only within a specific post type, then all you have to do is simply copy and paste the following code into your theme’s functions.php file. Remember to change the post type name on line 4 and you are done.
1 2 3 4 5 6 7 8 9 |
function SearchFilter($query) { if ($query->is_search) { // Insert the specific post type you want to search $query->set('post_type', 'feeds'); } return $query; } // This filter will jump into the loop and arrange our results before they're returned add_filter('pre_get_posts','SearchFilter'); |
Snippet Source/Credit: Hongkiat
How To Automatically Add Twitter And Facebook Buttons To Your Posts
Adding the following snippet to your theme’s functions.php file, you will be able to add Twitter and Facebook buttons to your posts. It will display both Facebook and Twitter buttons at the bottom of this post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function share_this($content){ if(!is_feed() && !is_home()) { $content .= '<div class="share-this"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a> <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <div class="facebook-share-button"> <iframe src="http://www.facebook.com/plugins/like.php?href='. urlencode(get_permalink($post->ID)) .'&layout=button_count&show_faces=false&width=200&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe> </div> </div>'; } return $content; } add_action('the_content', 'share_this'); |
Snippet Source/Credit: WPRecipes
How To Remove Login Shake Effect At The Time When Error Occurs
Using the following snippet will let you remove the login shake effect when error occurs. Simply paste the following code in your theme’s functions.php file and you are done.
1 2 3 4 |
function wps_login_error() { remove_action('login_head', 'wp_shake_js', 12); } add_action('login_head', 'wps_login_error'); |
Snippet Source/Credit: WordPress Support Forum
How To Add .pdf Support To Your WordPress Blog Media Manager
Copy and paste the following snippet into your theme’s functions.php file and you are done.
1 2 3 4 5 6 7 8 9 |
modify_post_mime_types( $post_mime_types ) { // select the mime type, here: 'application/pdf' // then we define an array with the label values $post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF <span class="count">(%s)</span>', 'PDFs <span class="count">(%s)</span>' ) ); // then we return the $post_mime_types variable return $post_mime_types; } // Add Filter Hook add_filter( 'post_mime_types', 'modify_post_mime_types' ); |
Snippet Source/Credit: WP Tuts
Making Translatable JavaScript Strings On Your WordPress Theme
With the help of snippet below, you will be able to make translatable JavaScript strings on your WordPress theme. Make sure you paste the following code into your function.php file.
1 2 3 4 5 6 7 8 |
function prefix_enqueue_custom_script(){ wp_register_script( 'prefix_custom_script', plugin_dir_url( __FILE__ ) .'js/custom-script.js', array( 'jquery' ) ); wp_enqueue_script( 'prefix_custom_script' ); wp_localize_script( 'prefix_custom_script', 'prefix_object_name', array( 'upload' => __( 'upload', 'textdomain' ), 'remove' => __( 'remove', 'textdomain' ) ) ); } |
Snippet Source/Credit: WPTheming.com