Temporary Maintenance
The following snippet will let you temporarily close down your site for visits while your website can still be accessed by admins resulting in letting you do the changes that you are planning for
1 2 3 4 5 6 7 8 |
// Temp Maintenance - with http response 503 (Service Temporarily Unavailable) // This will only block users who are NOT an administrator from viewing the website. function wp_maintenance_mode(){ if(!current_user_can('edit_themes') || !is_user_logged_in()){ wp_die('Maintenance, please come back soon.', 'Maintenance - please come back soon.', array('response' => '503')); } } add_action('get_header', 'wp_maintenance_mode'); |
Add featured images to WordPress feeds
The snippet below will let you add featured images to WordPress feeds.
1 2 3 4 5 6 7 8 9 |
function rss_post_thumbnail($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = get_the_post_thumbnail($post->ID) . $content; } return $content; } add_filter('the_excerpt_rss', 'rss_post_thumbnail'); add_filter('the_content_feed', 'rss_post_thumbnail'); |
Set Minimal Comment Limit In WordPress
The following snippet will let you set minimal comment limit in WordPress.
1 2 3 4 5 6 7 8 9 |
add_filter( 'preprocess_comment', 'minimal_comment_length' ); function minimal_comment_length( $commentdata ) { $minimalCommentLength = 20; if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength ) { wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' ); } return $commentdata; } |
Allow PHP in WordPress Text Widgets
The following snippet will allow PHP in WordPress text widget.
1 2 3 4 5 6 7 8 9 10 |
function php_text($text) { if (strpos($text, '<' . '?') !== false) { ob_start(); eval('?' . '>' . $text); $text = ob_get_contents(); ob_end_clean(); } return $text; } add_filter('widget_text', 'php_text', 99); |