Tag Archives: Web Host

How to display your average feed readers

As usual, the first thing to do is to paste the function in your functions.php file: function get_average_readers($feed_id,$interval = 7){ $today = date('Y-m-d', strtotime("now")); $ago = date('Y-m-d', strtotime("-".$interval." days")); $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $feed_url); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($data); $fb = $xml->feed->entry['circulation']; $nb = 0; foreach($xml->feed->children() as [...]

Add categories or tags to post programatically

The first thing to do is to create an array of categories id. Once done, you simply have to use the wp_set_object() function, which take 3 parameters: The post id, an array of categories to add to the post, and the taxonomy type (category in this example). $category_ids = array(4, 5, 6); wp_set_object_terms( $post_id, $category_ids, [...]

Display dates as “time ago”, the easy way

To display human readable dates on your blog, you have to use the human_time_diff() function. The following piece of code will show a post date like “Posted 6 days ago”. Paste it anywhere within the loop, save the file, and you’re done. Posted <?php echo human_time_diff(get_the_time(‘U’), current_time(‘timestamp’)) . ‘ ago’; ?> Credits: PHP Snippets. Looking [...]

WordPress hack: Use includes in your posts or pages

The first step is to paste the following code in your function.php file: function digwp_includeContentShortcode($atts) { $thepostid = intval($atts[postidparam]); $output = ''; query_posts("p=$thepostid&post_type=page"); if (have_posts()) : while (have_posts()) : the_post(); $output .= get_the_content($post->ID); endwhile; else: // failed, output nothing endif; wp_reset_query(); return [...]

How to programatically remove WordPress dashboard widgets

Simply paste the following into your functions.php file. The code will remove all dashboard widgets, so you should comment lines related to wigets you’d like to keep. function remove_dashboard_widgets() { global $wp_meta_boxes; unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']); unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } if (!current_user_can('manage_options')) { add_action('wp_dashboard_setup', 'remove_dashboard_widgets' ); } Thanks to NoScope for this code! By [...]

How to automatically create a custom field when a post is published

Paste the code below into your functions.php file. The only thing you have to do is to edit the cutsom field name on line 6. add_action(‘publish_page’, ‘add_custom_field_automatically’); add_action(‘publish_post’, ‘add_custom_field_automatically’); function add_custom_field_automatically($post_ID) { global $wpdb; if(!wp_is_post_revision($post_ID)) { add_post_meta($post_ID, ‘field-name’, ‘custom value’, true); } } Thanks to wpCanyon for this cool tip! Looking for WordPress hosting? Try [...]

WordPress hack: Display post thumbnail in your RSS feed

Simply paste the following code in your functions.php file. The post thumbnail should be visible once you saved the file. function diw_post_thumbnail_feeds($content) { global $post; if(has_post_thumbnail($post->ID)) { $content = '<div>' . get_the_post_thumbnail($post->ID) . '</div>' . $content; } return $content; } add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds'); add_filter('the_content_feed', 'diw_post_thumbnail_feeds'); Thanks to Jeff Starr for this great tip! Looking for WordPress [...]

Weblog Tools Collection: WordPress 3.0 Walkthrough: Getting Started with Multisite

WordPress 3.0 Walkthrough: Multsite Multisite is the most talked about new feature in WordPress 3.0 – the WordPress team has folded the functionality of WordPress Multiuser into the main WordPress project. So how do you use it? This tutorial assumes your are comfortable using FTP clients such as Filezilla and doing basic edits of WordPress [...]

WordPress hack: Remove admin name in comments class

This code simply have to be pasted in your functions.php file to work: function remove_comment_author_class( $classes ) { foreach( $classes as $key => $class ) { if(strstr($class, "comment-author-")) { unset( $classes[$key] ); } } return $classes; } add_filter( 'comment_class' , 'remove_comment_author_class' ); Thanks to C. Bavota for this interesting piece of code! Looking for WordPress [...]

WordPress tip: Automatically empty Trash

Simply open your wp-config.php file (located at the root of your WOrdPress install) and paste the following code: define(‘EMPTY_TRASH_DAYS’, 10 ); The second parameter is when to empty trash, in days. Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free! WordPress tip: Automatically empty Trash [...]

Powered by Yahoo! Answers