Tag Archives: Jean Baptiste

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 [...]

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 [...]

WordPress hack: Insert comments programatically

The following code can be pasted anywhere on your theme files. Once this code is executed, it will add a new comment into WordPress database. The returned value is the comment ID, or 0 if a problem happenned. $data = array( ‘comment_post_ID’ => 1, ‘comment_author’ => ‘admin’, ‘comment_author_email’ => ‘admin@admin.com’, ‘comment_author_url’ => ‘http://www.catswhocode.com’, ‘comment_content’ => [...]

WordPress hack: Get popular posts by comments count

Simply paste the following code where you want to display your most popular posts to be displayed: $pop = $wpdb->get_results("SELECT id, post_title, comment_count FROM {$wpdb->prefix}posts WHERE post_type='post' ORDER BY comment_count DESC LIMIT 10"); <ul> foreach($pop as $post) : ?> <li> <?php echo $post->post_title; ?> </li> <?php endforeach; ?> </ul> Thanks to Neil Skoglund for this [...]

WordPress tip: Quickly secure plugin files

Paste the following in your .htaccess file. Don’t forget to backup the file before edition! <Files ~ "\.(js|css)$"> order allow,deny allow from all </Files> This recipe has been submitted by Greg Winiarski. Thanks for your contribution! Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free! [...]

WordPress tip: Insert custom content after each post

You just have to paste the following code into your functions.php and save the file. Once done, custom content will be inserted below each of your posts. function add_post_content($content) { if(!is_feed() && !is_home()) { $content .= '<p>This article is copyright &copy; '.date('Y').'&nbsp;'.bloginfo('name').'</p>'; } return $content; } add_filter('the_content', 'add_post_content'); Thanks to Jeff Starr for the great [...]

How to display Twitter-like “time ago” on your WordPress blog

The first thing to do is to create the function. To do so, paste the following into your functions.php file: function time_ago( $type = ‘post’ ) { $d = ‘comment’ == $type ? ‘get_comment_time’ : ‘get_post_time’; return human_time_diff($d(‘U’), current_time(‘timestamp’)) . ” ” . __(‘ago’); } Once done, you can use the function in your theme [...]

WordPress tip: Allow contributors to upload files

Nothng hard with this code: The only thing you have to do is to paste it in your functions.php file: if ( current_user_can(‘contributor’) && !current_user_can(‘upload_files’) ) add_action(‘admin_init’, ‘allow_contributor_uploads’); function allow_contributor_uploads() { $contributor = get_role(‘contributor’); $contributor->add_cap(‘upload_files’); } Big thanks to Altaf Sayani for his contribution to WpRecipes! Looking for WordPress hosting? Try [...]

Powered by Yahoo! Answers