Display information about your multisite install
To display information about your multisite install, simply paste the following piece of code where you want the info to be display.
1 2 3 4 5 |
<?php if( is_multisite() ): ?> The <a href="<?php echo esc_url( get_site_option( 'siteurl' ) ); ?>"><?php echo esc_html( get_site_option( 'site_name' ) ); ?> network</a> currently powers <strong><?php echo get_blog_count(); ?></strong> websites and <strong><?php echo get_user_count(); ?></strong> users. <?php endif; ?> |
Source: Kevin Leary
Automatically remove p tags on images
Simply paste the following code on your theme functions.php file, save it, and the <p> tags are gone permanently.
1 2 3 4 5 6 7 |
function filter_ptags_on_images($content){ return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); } add_filter('the_content', 'filter_ptags_on_images'); |
Source: James
Automatically email guest authors when their posts are published
Copy the code below and paste it on your functions.php file and you will be able to automatically email contributors when their posts are published.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function wpr_authorNotification($post_id) { $post = get_post($post_id); $author = get_userdata($post->post_author); $message = " Hi ".$author->display_name.", Your post, ".$post->post_title." has just been published. Well done! "; wp_mail($author->user_email, "Your article is online", $message); } add_action('publish_post', 'wpr_authorNotification'); |
Source: Daniel Pataki
Create a login form shortcode
Paste the code below into your functions.php file which lets you create a login form shortcode for your WordPress blog.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
function devpress_login_form_shortcode() { if ( is_user_logged_in() ) return ''; return wp_login_form( array( 'echo' => false ) ); } function devpress_add_shortcodes() { add_shortcode( 'devpress-login-form', 'devpress_login_form_shortcode' ); } add_action( 'init', 'devpress_add_shortcodes' ); function devpress_login_form_shortcode() { if ( is_user_logged_in() ) return ''; return wp_login_form( array( 'echo' => false ) ); } function devpress_add_shortcodes() { add_shortcode( 'devpress-login-form', 'devpress_login_form_shortcode' ); } add_action( 'init', 'devpress_add_shortcodes' ); |
Once done, add the following shortcode on the page where you want to have the login form added.
1 |
[devpress-login-form] |
Source: DevPress
Reduce spam by using .htaccess
Simply paste the following lines into your .htaccess file but also make sure you do take the backup of the whole of your website before putting this shortcode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{REQUEST_URI} .wp-comments-post\.php* RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L] </IfModule> |
Source: AllGuru.net
Photo Credit: Flickr/Mike Renlund