The following snippet will let you solve multiple loops problem in WordPress.
1 | <?php wp_reset_query(); ?> |
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet
The following snippet will let you solve multiple loops problem in WordPress.
1 | <?php wp_reset_query(); ?> |
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet below, you will be able to automatically notify members on new posts in WordPress.
1 2 3 4 5 6 7 8 | function email_members($post_ID) { global $wpdb; $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $users = implode(",", $usersarray); mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com'); return $post_ID; } add_action('publish_post', 'email_members'); |
Snippet Source/Credit: WordPress Codex
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following lines of codes below, you will be able to add an extra contact methods to user profiles in WordPress.
1 2 3 4 5 6 | add_filter('user_contactmethods', 'my_user_contactmethods'); function my_user_contactmethods($user_contactmethods){ $user_contactmethods['twitter'] = 'Twitter Username'; $user_contactmethods['facebook'] = 'Facebook Username'; return $user_contactmethods; } |
Snippet Source/Credit: TutsPlus
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to restrict the use of HTML in comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to automatically notify members on new posts in WordPress.
1 2 3 4 5 6 7 8 | function email_members($post_ID) { global $wpdb; $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $users = implode(",", $usersarray); mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com'); return $post_ID; } add_action('publish_post', 'email_members'); |
Snippet Source/Credit: WordPress Codex
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to remove widgets from WordPress dashboard.
1 2 3 4 5 6 7 | //Remove unwanted widgets from Dashboard function remove_dashboard_widgets() { global$wp_meta_boxes; unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } add_action('wp_dashboard_setup', 'remove_dashboard_widgets'); |
Snippet Source/Credit: WP Guru
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following lines of code, you will be able to add custom Pinterest button in your WordPress website. All you have to do is to add to your header above the body tag:
1 | <script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script> |
followed by Edit and add to your page where you want your button to appear.
1 | <div class="socialIcon-box"><a href="http://pinterest.com/pin/create/button/?url=http%3A%2F%2Fyourdomain.com&media=<?php bloginfo(template_directory); ?>/images/youricon.png&description=Site%20Name%20and%20Description" class="pin-it-button" count-layout="horizontal"><img src="<?php bloginfo(template_directory); ?>/images/youricon.png" /></a></div> |
Snippet Source/Credit: flashalexander.com
By Editorial Staff in Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
The following snippet will let you set WordPress post expiration code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php //to check against expiration date; $timestamp = strtotime("now + 8 hours"); $currentdate = date('YmdHis', $timestamp); $expirationdate = get_post_custom_values('expiration'); if (is_null($expirationdate)) { $expirestring = '30005050235959'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP; } else { if (is_array($expirationdate)) { $expirestringarray = implode($expirationdate); } $markup = array("/",":"," "); $expirestring = str_replace($markup,"",$expirestringarray); } //else if (( $expirestring > $currentdate ) || (is_archive())) { ?> <?php } //end if for expiration; ?> |
Snippet Source/Credit: nrbet.com
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
The following snippet will let you change WordPress role access to menu and widgets.
1 2 3 4 5 6 | <?php // get the the role object $role_object = get_role('editor'); // add $cap capability to this role object $role_object->add_cap('edit_theme_options'); ?> |
Snippet Source/Credit: WP-Snippets.com
By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
The following snippet will let you delete post revision in your WordPress website.
1 2 3 4 | $wpdb->query( " DELETE FROM $wpdb->posts WHERE post_type = 'revision' " ); |
Snippet Source/Credit: Hardeep Asrani