Change WordPress “from” email header
Adding the following shortcode will let you use your real name or username instead of by default set WordPress email address which looks like as WordPress@yoursitename.com.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function res_fromemail($email) { $wpfrom = get_option('admin_email'); return $wpfrom; } function res_fromname($email){ $wpfrom = get_option('blogname'); return $wpfrom; } add_filter('wp_mail_from', 'res_fromemail'); add_filter('wp_mail_from_name', 'res_fromname'); |
Source: KeenTricks
Redirecting your homepage to the first post
Simply paste the code to your site’s homepage file (mainly it is index.php file) and you will be able to redirect your homepage to the first post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php /* home.php (Blog Home Page): Redirect To First Post */ if (have_posts()) { while (have_posts()) { the_post(); wp_redirect(get_permalink()); } } ?> |
Source: Ashton Sanders
Automatically add Twitter and Facebook buttons to your posts
Adding the following shortcode to your functions.php file will let you automatically add Twitter and Facebook buttons to your posts.
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 |
function share_this($content){ if(!is_feed() && !is_home()) { $content .= '<div> <a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a> <script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> <div> <iframe src="http://www.facebook.com/plugins/like.php?href='. urlencode(get_permalink($post->ID)) .'&layout=button_count&show_faces=false&width=200&action=like&colorscheme=light&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe> </div> </div>'; } return $content; } add_action('the_content', 'share_this'); |
Source: Dev7Studios
How to automatically add a search field to your navigation menu
On copying the code to your theme’s functions.php file you will be able to add a search filed automatically to your navigation menu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
add_filter('wp_nav_menu_items','add_search_box', 10, 2); function add_search_box($items, $args) { ob_start(); get_search_form(); $searchform = ob_get_contents(); ob_end_clean(); $items .= '<li>' . $searchform . '</li>'; return $items; } |
Source: Ronald
How to get category slug using category ID
Adding the following code to your theme’s functions.php file will let you get category slug using category ID.
1 2 3 4 5 6 7 8 9 |
function get_cat_slug($cat_id) { $cat_id = (int) $cat_id; $category = &get_category($cat_id); return $category->slug; } |
Once done, you can call the function as shown below:
1 |
<?php echo get_cat_slug(5); ?> |
This will display the slug for the category with the ID 5.
Source: Ken Rosaka
How to count your blogroll links
Simply paste the following code where you want the count to be displayed and you will be able to count your blogroll links.
1 2 3 4 5 6 7 8 9 |
<?php $numlinks = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->links WHERE link_visible = 'Y'"); if (0 < $numlinks) $numlinks = number_format($numlinks); echo $numlinks; ?> |
Source: Jeff Starr
Photo Credit: Flickr/hackNY.org