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 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 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 Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Using the following snippet, you will be able to get email alerts for 404 pages in WordPress.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <?php // WP 404 ALERTS @ http://wp-mix.com/wordpress-404-email-alerts/ // set status header("HTTP/1.1 404 Not Found"); header("Status: 404 Not Found"); // site info $blog = get_bloginfo('name'); $site = get_bloginfo('url') . '/'; $email = get_bloginfo('admin_email'); // theme info if (!empty($_COOKIE["nkthemeswitch" . COOKIEHASH])) { $theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]); } else { $theme_data = wp_get_theme(); $theme = clean($theme_data->Name); } // referrer if (isset($_SERVER['HTTP_REFERER'])) { $referer = clean($_SERVER['HTTP_REFERER']); } else { $referer = "undefined"; } // request URI if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) { $request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); } else { $request = "undefined"; } // query string if (isset($_SERVER['QUERY_STRING'])) { $string = clean($_SERVER['QUERY_STRING']); } else { $string = "undefined"; } // IP address if (isset($_SERVER['REMOTE_ADDR'])) { $address = clean($_SERVER['REMOTE_ADDR']); } else { $address = "undefined"; } // user agent if (isset($_SERVER['HTTP_USER_AGENT'])) { $agent = clean($_SERVER['HTTP_USER_AGENT']); } else { $agent = "undefined"; } // identity if (isset($_SERVER['REMOTE_IDENT'])) { $remote = clean($_SERVER['REMOTE_IDENT']); } else { $remote = "undefined"; } // log time $time = clean(date("F jS Y, h:ia", time())); // sanitize function clean($string) { $string = rtrim($string); $string = ltrim($string); $string = htmlentities($string, ENT_QUOTES); $string = str_replace("\n", "<br>", $string); if (get_magic_quotes_gpc()) { $string = stripslashes($string); } return $string; } $message = "TIME: " . $time . "\n" . "*404: " . $request . "\n" . "SITE: " . $site . "\n" . "THEME: " . $theme . "\n" . "REFERRER: " . $referer . "\n" . "QUERY STRING: " . $string . "\n" . "REMOTE ADDRESS: " . $address . "\n" . "REMOTE IDENTITY: " . $remote . "\n" . "USER AGENT: " . $agent . "\n\n\n"; mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email"); ?> |
Snippet Source/Credit: WP Mix
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 news feed in WordPress dashboard.
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 | add_action('wp_dashboard_setup', 'my_dashboard_widgets'); function my_dashboard_widgets() { global $wp_meta_boxes; // remove unnecessary widgets // var_dump( $wp_meta_boxes['dashboard'] ); // use to get all the widget IDs unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'], $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'], $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] ); // add a custom dashboard widget wp_add_dashboard_widget( 'dashboard_custom_feed', 'News from 10up', 'dashboard_custom_feed_output' ); //add new RSS feed output } function dashboard_custom_feed_output() { echo '<div class="rss-widget">'; wp_widget_rss_output(array( 'url' => 'http://www.get10up.com/feed', 'title' => 'What\'s up at 10up', 'items' => 2, 'show_summary' => 1, 'show_author' => 0, 'show_date' => 1, )); echo "</div>"; } |
Snippet Source/Credit: Smashing Magazine
By Editorial Staff in Featured, WordPress No Comments Tags: Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
The following snippet below will let you use gravatar image as WordPress favicon.
1 2 3 4 5 6 | // add gravatar favicon to site, 16x16 favicon.ico function snix_add_favicon() { $GetTheHash = md5(strtolower(trim('scott@scottnix.com'))); ?><link rel="shortcut icon" href="<?php echo 'http://www.gravatar.com/avatar/' . $GetTheHash . '?s=16;'; ?>" /><?php } add_action('wp_head', 'snix_add_favicon'); |
Snippet Source/Credit: forrst.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 Featured, WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets
Adding this snippet to your theme’s functions.php file will let you show content only for logged in users.
1 2 3 4 5 6 7 8 9 10 | <?php add_shortcode("hide","hide_shortcode"); function hide_shortcode($x,$text=null){ if(!is_user_logged_in()){ return "You have to been registered and logged in to see this content"; }else{ return do_shortcode($text); } } ?> |
Snippet Source/Credit: Snipplr