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

Remove News Feed In WordPress Dashboard

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

The following snippet will let you remove news feed from your 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 Display Twitter Followers Image List

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

Using the following snippet, one can display Twitter followers image list.

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
<?php
//replace $options['twitter'] with the twitter Username you want to use.
?>
<?php
$xmlfollowersUrl = 'http://api.twitter.com/1/statuses/followers/'.$options['twitter'].'.xml';
if (file_exists(WP_CONTENT_DIR.'/uploads/twitter_followers.xml')) {
$data = unserialize(file_get_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml'));
if ($data['timestamp'] > time() - 120 * 60) {
$twitter_followers = $data['twitter_result'];
}
}
if (!$twitter_followers) { // cache doesn't exist or is older than 10 mins
    $twitter_followers = file_get_contents($xmlfollowersUrl); // or whatever your API call is
    $data = array ('twitter_followers' => $twitter_followers, 'timestamp' => time());
    file_put_contents(WP_CONTENT_DIR.'/uploads/twitter_followers.xml', serialize($data));
}
$dom = new DOMDocument;
$s = simplexml_load_string($twitter_followers);
$count = 0;
echo '<ul class="seguidores">';
foreach($s->user as $follower):
if(++$count > 50){
break;
}
echo '<li><a target="_blank" href="http://www.twitter.com/'.$follower->screen_name.'"><img width="32" height="32" src="'.$follower->profile_image_url.'" alt="'.$follower->name.'" title="'.$follower->name.': '.$follower->status->text.'"/></a></li>';
endforeach;
echo '</ul>';
?>

Snippet Source/Credit: Snipplr

How To Add PayPal Functionality In WordPress

November 7, 2020 By Editorial Staff in WordPress No Comments Tags: Code, Code Snippet, PayPal, Snippet, WordPress, WordPress Snippet, WordPress Snippets

Using the following snippet will let you add PayPal button to your WordPress website. Remember to add the snippet to your theme’s functions.php file and you are done.

1
2
3
4
5
6
7
8
9
10
11
function cwc_donate_shortcode( $atts ) {
    extract(shortcode_atts(array(
        'text' => 'Make a donation',
        'account' => 'REPLACE ME',
        'for' => '',
    ), $atts));
    global $post;
    if (!$for) $for = str_replace(" ","+",$post->post_title);
    return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation+for+'.$for.'">'.$text.'</a>';
}
add_shortcode('donate', 'cwc_donate_shortcode');

Snippet Source/Credit: Snipplr

How To Show Top Level And Child Pages In WordPress

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

The following snippet will let you show top level and child pages in WordPress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<ul><?php $parent_title = get_the_title($post->post_parent);?>
<li><a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a></li></ul>
          <?php
if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
$children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
if ($children) { ?>
<ul id="subnav">
<?php echo $children; ?>
</ul>
<?php } ?>

Setting Up WordPress Post Expiration Code

October 21, 2020 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

How To Have A/B Split Google Optimizer For WordPress

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

The following snippet will like you to have A/B split Google optimizer testing done for 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
//Custom Headers for A/B Split Landing Pages
function insert_splittest_header() {
if (is_page(8582)) { ?>
<!-- Google Website Optimizer Control Script -->
<script>
function utmx_section(){}function utmx(){}
(function(){var k='0785944995',d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n.
length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
d.write('<sc'+'ript src="'+
'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
</script><script>utmx("url",'A/B');</script>
<!-- End of Google Website Optimizer Control Script -->
<!-- Google Website Optimizer Tracking Script -->
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['gwo._setAccount', 'UA-23025259-1']);
  _gaq.push(['gwo._trackPageview', '/0785944995/test']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<!-- End of Google Website Optimizer Tracking Script -->
<?php } }
add_action('wp_head','insert_splittest_header',0);
// Customer Footer for final page - the 'thank you'
function insert_B_footer () {
if (is_page(9161)) { ?>
<!-- Google Website Optimizer Tracking Script -->
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['gwo._setAccount', 'UA-23025259-1']);
  _gaq.push(['gwo._trackPageview', '/0785944995/test']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<!-- End of Google Website Optimizer Tracking Script -->
<?php } }
add_action('wp_footer','insert_B_footer');

Snippet Source/Credit: Snipplr

Renaming A Folder In WordPress

October 7, 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 rename WordPress folder.

1
2
3
4
define ( 'WP_CONTENT_FOLDERNAME', 'public' );
define ( 'WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define ( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' );
define ( 'WP_CONTENT_URL', WP_SITEURL . WP_CONTENT_FOLDERNAME );

Snippet Source/Credit: Snipplr

Disabling Comments In WordPress

September 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 disable comments in WordPress permanently.

1
<?php return false; ?>

Snippet Source/Credit: aotearoawebdesign.co.nz

Deleting Trash Permanently In WordPress

September 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 trash on daily basis in WordPress.

1
define('EMPTY_TRASH_DAYS', 1);

Note: Make sure that you do replace 1 by X to empty spam comments automatically every X days.

Show Content For Logged In Users In WordPress

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

«< 3 4 5 6 7 >»

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