How to easily enable/disable debug mode in WordPress
WordPress comes with a debug mode by which you will be able to grab the information which lets you know that what is wrong. In order to enable or disable the mode, all you have to do is to copy and paste the following snippet in your theme’s wp-config.php file.
1 2 3 |
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.example.com/contact?debug=debug |
Snippet Source/Credit: Joost de Valk
How To Get Rid Of HTML In Comments
People often put their HTML links in the comments in an urge to get a link back. Well, this sounds frustrating mainly for the website owner but not the people who perform such task. Well, if you wish to get rid of HTML in comments completely, then all you have to do is to copy and paste the snippet in their theme’s functions.php file.
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 34 35 36 37 |
// 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 make term edition easier
While WordPress does come with much in-built functionality but sometimes you require more, say like quick edition of a term (mainly category, tag or custom term). In order to achieve the above, all you have to do is to simply paste the following snippet in your theme’s functions.php file.
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 34 35 |
if ( !function_exists('edit_term_link') ) { function edit_term_link( $link = '', $before = '', $after = '', $term = null ) { if ( $term == null ) { global $wp_query; $term = $wp_query->get_queried_object(); } $tax = get_taxonomy( $term->taxonomy ); if ( !current_user_can($tax->cap->edit_terms) ) return; if ( empty($link) ) $link = __('Edit This'); $link = '<a href="' . get_edit_tag_link( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>'; echo $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; } } |
Once saved, add the following line of snippet on any category, tag or taxonomy template:
1 |
<?php edit_term_link(); ?> |
Snippet Source/Credit: Joost de Valk
How To Rearrange WordPress Categories Order
Adding the following snippet to your theme’s functions.php file, you will be able to rearrange WordPress categories order, completely the way you want it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php $categories = get_terms('books_category'); for( $i=0; $i<sizeof($categories); $i++ ){ if ( $categories[$i]->name == 'New Publications' ) : $latest = array($categories[$i]); unset($categories[$i]); endif; } if( isset($latest) ) array_splice( $categories, 0, 0, $latest ); ?> |
Snippet Source/Credit: Sebastian
How to set a maximum word count on post titles
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 8 9 10 11 12 13 |
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
How To Use WordPress Shortcodes In Theme Files
A person who has got even a little knowledge of WordPress does understand the importance of WordPress shortcodes. While, everyone who are aware of shortcodes, definitely love them out but unluckily, shortcodes by default can be use only in post and page editor area and not in theme files. But, well with the help of this snippet below, you can use a shortcode in a theme file too, all you have to do is to use the do_shortcode() function as shared below.
1 |
<?php echo do_shortcode("[your_shortcode]"); ?> |