Code & Me
WordPress Code Snippet Repository
  • Home
  • Featured
  • Recently Added
  • About
  • Contact

Removing Widgets From WordPress Dashboard

January 19, 2021 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

Adding Custom Pinterest Button In WordPress Website

January 12, 2021 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

Setting Up WordPress Post Expiration Code

January 5, 2021 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

Changing WordPress Role Access To Menu And Widgets

December 30, 2020 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

Deleting Post Revisions In WordPress

December 23, 2020 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

How To Display WordPress Excerpt Dynamic Length

By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, Snippet, WordPress, WordPress Snippet, WordPress Snippets

The following snippet display the WordPress excerpt dynamic length.

1
2
3
4
5
6
7
8
9
10
11
12
function ms_rp_excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(' ', $excerpt).'...';
}
else {
$excerpt = implode(' ', $excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
return $excerpt;
}

Snippet Source/Credit: Snipplr

Getting Email Alerts For 404 Pages In WordPress

December 16, 2020 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

Removing News Feed In WordPress Dashboard

December 9, 2020 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

How To Use Gravatar Image As WordPress Favicon

December 2, 2020 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

 

How To Have Custom Favicon For Your WP-Admin

November 28, 2020 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 have custom favicon for your WP-admin.

1
2
3
4
function admin_favicon() {
echo '<link rel="shortcut icon" type="image/x-icon" href="' . get_bloginfo('template_directory') . '/images/favicon.ico" />';
}
add_action( 'admin_head', 'admin_favicon' );

Snippet Source/Credit: Snipplr

«< 2 3 4 5 6 >»

Recently Added Snippets

  • How To Set Role And Capabilities In WordPress
  • How To Set WordPress Options As Value
  • List Author Comments On Author Page
  • WordPress Display Page
  • Removing WordPress Version From Head And Feeds

Search The Snippet

Featured Snippets

  • How To Set WordPress Options As Value
  • WordPress Display Page
  • Removing WordPress Version From Head And Feeds
  • Delete Link In Comments In Your WordPress Website
  • Creating Database For Your WordPress Website
Code & Me
  • About
  • Recently Added
  • Advertise
  • Terms
  • Privacy Policy
  • Contact
© 2014-19 CodeAndMe.
Proud Member Of G2One Network Family.

↑ Back to top