WordPress hack: Get rid of HTML in comments
Aug 31, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
Just paste the code below into your functions.php file. If you prefer to use a plugin with the same functionality, you can grab one here . // This will occur when the comment is posted function plc_comment_post( $incoming_comment ) { // convert everything in a comment to display literally $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']); // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] ); return( $incoming_comment ); } // This will occur before a comment is displayed function plc_comment_display( $comment_to_display ) { // Put the single quotes back in $comment_to_display = str_replace( ''', "'", $comment_to_display ); return $comment_to_display; } add_filter( 'preprocess_comment', 'plc_comment_post', '', 1); add_filter( 'comment_text', 'plc_comment_display', '', 1); add_filter( 'comment_text_rss', 'plc_comment_display', '', 1); add_filter( 'comment_excerpt', 'plc_comment_display', '', 1); Thanks to Peter’s useful crap for this nice code! Looking for WordPress hosting?
Direct Link Read the rest of this entry »
Tags: archives, article, china, china-suppliers, Code, contribute, CSS, development, HTML, JavaScript, PHP, related, repeat, themes, Tutorials
How to easily enable/disable debug mode in WordPress
Aug 27, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
The first thing to do is to add the following code to your wp-config.php file. This file is located at the root of your WordPress install. if ( isset($_GET['debug']) && $_GET['debug'] == ‘debug’) define(‘WP_DEBUG’, true); Once done, simply add a GET parameter to the url of the page you’d like to debug, as shown below: http://www.wprecipes.com/contact?debug=debug Thanks to Joost de Valk for this great tip! Looking for WordPress hosting?
Direct Link Read the rest of this entry »
Tags: archives, article, china, china-suppliers, contribute, CSS, Design, development, HTML, JavaScript, PHP, related, repeat, themes, Tutorials
WordPress function: Get category ID using category name
Jul 29, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
As usual, let’s start by pasting the function in your functions.php file: function get_category_id($cat_name){ $term = get_term_by(‘name’, $cat_name, ‘category’); return $term-> term_id; } Once you saved the file, just call the function with your category name as a parameter. Example: $category_ID = get_category_id(‘WordPress Tutorials’); Looking for WordPress hosting? Try WP Web Host .
Direct Link Read the rest of this entry »
Tags: archives, banner, canvas-theme, category id, china-suppliers, contribute, development, JavaScript, magic-members, purchase, themes, Tutorials, wordpress-discounts
Add categories or tags to post programatically
Jul 19, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
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, ‘category’); Adding tags to a post is extremely easy as well.
Direct Link Read the rest of this entry »
Tags: article, canvas-theme, china, china-suppliers, contribute, CSS, development, HTML, JavaScript, magic-members, PHP, purchase, Tips, Tutorials, wordpress-discounts
Display dates as “time ago”, the easy way
Jul 5, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
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.
Direct Link Read the rest of this entry »
Tags: archives, article, banner, canvas-theme, china, china-suppliers, christmas, contribute, HTML, JavaScript, magic-members, PHP, purchase, the-easy-way, wordpress-discounts
How to programatically remove WordPress dashboard widgets
Jun 23, 2010 CSS, General, HTML, JavaScript, PHP, Tutorials, Wordpress
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 the way, did you had a look to my latest post on CatsWhoCode about WP 3.0 custom post types?
Direct Link Read the rest of this entry »
Tags: archives, article, canvas-theme, china, Code, contribute, CSS, development, wordpress-discounts
How to automatically create a custom field when a post is published
Jun 15, 2010 CSS, HTML, JavaScript, PHP, Tutorials, Wordpress
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?
Direct Link Read the rest of this entry »
Tags: article, china-suppliers, Code, contribute, custom, custom fields, magic-members, Plugin, purchase, related, themes, Tutorials, wordpress-discounts
WordPress hack: Display post thumbnail in your RSS feed
Jun 11, 2010 CSS, HTML, JavaScript, PHP, Tutorials, Wordpress
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>' .
Direct Link Read the rest of this entry »
Tags: archives, article, china-suppliers, contribute, JavaScript, magic-members, purchase, repeat, themes
10 PHP code snippets for working with strings
Jun 7, 2010 Ajax, CSS, General, HTML, JavaScript, PHP, Resources, Tutorials, Wordpress
Automatically remove html tags from a string On user-submitted forms, you may want to remove all unnecessary html tags. Doing so is easy using the strip_tags() function: $text = strip_tags($input, “”); Source: http://phpbuilder.com/columns/Jason_Gilmore060210.php3?page=2 Get the text between $start and $end This is the kind of function every web developer should have in their toolbox for future use: give it a string, a start, and an end, and it will return the text contained with $start and $end. function GetBetween($content,$start,$end){ $r = explode($start, $content); if (isset($r[1])){ $r = explode($end, $r[1]); return $r[0]; } return ”; } Source: http://www.jonasjohn.de/snippets/php/get-between.htm Transform URL to hyperlinks If you leave a URL in the comment form of a WordPress blog, it will be automatically transformed into a hyperlink.
Direct Link Read the rest of this entry »
Tags: Ajax, baptiste-jung, Code, contribute, CSS, Resources, Tutorials, Web Development






