How To Prevent WordPress To Compress Your JPG Files
The following snippet will let you prevent WordPress to compress your JPG files.
1 |
add_filter('jpeg_quality', function($arg){return 100;}); |
Snippet Source/Credit: WP Snippets
How To Have WordPress Pagination In Your Website Without The Use Of Any Plugins
The following snippet will let you have WordPress paginate in your website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
global $wp_query; $total = $wp_query->max_num_pages; // only bother with the rest if we have more than 1 page! if ( $total > 1 ) { // get the current page if ( !$current_page = get_query_var('paged') ) $current_page = 1; // structure of "format" depends on whether we're using pretty permalinks $format = empty( get_option('permalink_structure') ) ? '&page=%#%' : 'page/%#%/'; echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => $format, 'current' => $current_page, 'total' => $total, 'mid_size' => 4, 'type' => 'list' )); } |
Snippet Source/Credit: Smashing Magazine
How To Get Rid Of HTML In Comments
The following snippet will let you get rid of HTML in comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// This will occur when the comment is posted function plc_comment_post( $incoming_comment ) { // convert everything in a comment to display literally $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']); // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] ); return( $incoming_comment ); } // This will occur before a comment is displayed function plc_comment_display( $comment_to_display ) { // Put the single quotes back in $comment_to_display = str_replace( ''', "'", $comment_to_display ); return $comment_to_display; } add_filter( 'preprocess_comment', 'plc_comment_post', '', 1); add_filter( 'comment_text', 'plc_comment_display', '', 1); add_filter( 'comment_text_rss', 'plc_comment_display', '', 1); add_filter( 'comment_excerpt', 'plc_comment_display', '', 1); |
Snippet Source/Credit: TheBlog.ca
How To Easily Enable/Disable Debug Mode In WordPress
The following snippet will let you easily enable or disable debug mode in WordPress.
1 2 |
if ( isset($_GET['debug']) && $_GET['debug'] == 'debug') define('WP_DEBUG', true); |
Once done, simply add a GET parameter to the url of the page you’d like to debug:
1 |
http://www.wprecipes.com/contact?debug=debug |
Snippet Source/Credit: Joost de Valk
How to define a minimum word count per post
The following snippet will let you define a minimum word count per post.
1 2 3 4 5 6 7 8 |
function minWord($content){ global $post; $num = 100; //set this to the minimum number of words $content = $post->post_content; if (str_word_count($content) < $num) wp_die( __('Error: your post is below the minimum word count.') ); } add_action('publish_post', 'minWord'); |
Snippet Source/Credit: Pippin Williamson