Skip to main content

Posts

Showing posts from 2010

Highlight your Codes in WordPress Post with Google Syntax Highlighter

One of the problem most of the WordPress newbies face is highlighting their codes in the post. Some even go to the extend of writing their own extension for this purpose. When there are better solutions. Google Syntax Highlighter Plugin is one of the best plugin out there which does this task wonderfully. Its based on this work by Alex Gorbatchev . Here is a screen shot of what it can achieve

Allow contributor to Upload in Wordpress

In WordPress one of the most irritating thing that webmasters with multiple author feel is the lack of permission for the contributor to upload or insert images. When your blog is using post image its really hard as some one with a higher permission has to do the job. But there is a really simple trick to allow this. You just have to add this small piece of code to your functions.php file within your theme. 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'); } Wasn't that easy? For any doubts or suggestion use the comment form.

Insert Ads, Images or anything in RSS Feeds in WordPress

Monetizing RSS feeds has becomw a common practice, and many blogs do it to maximize their income. FeedBurner can insert AdSense ads into your feed items, but you need at least 500 subscribers to qualify, and you can’t use any ads other than the AdSense ads provided by FeedBurner. So what is the workaround? What if you want to show images in the feeds? Well thats quite easy! Follow these simple steps to perform this hack: Edit the functions.php file of your theme. If your theme doesn’t have a functions.php file, simply create one. Paste the following code into your functions.php file: <?php function insertAds($content) { $content = $content.'<hr /><a href="http://www.wprecipes.com">Have you visited WpRecipes today?</a><hr />'; return $content; } add_filter('the_excerpt_rss', 'insertAds'); add_filter('the_content_rss', 'insertAds'); ?> Save the file. You’re now displaying your ads in your RSS feed!

Using WordPress Comment Meta

Comment meta is such a wonderful addition to WordPress that allow us to extend the native comment form with additional fields. This comes very handy for the one's who is trying to create review sites etc. Unfortunately there’s no documentation added on the WP codex. For the purpose of demonstration we will be doing: add a check box to the comments form. show in the WordPress comments admin whether or not the checkbox was selected. indicate in the comment notification email whether or not the checkbox was selected. Adding the checkbox to the comments form is easy. To add the checkbox to the comments form open up your themes comments.php file and paste this into the area where you need it: <label><input id="publishc" name="publishc" tabindex="90" type="checkbox" value="this is the value I want to capture" /> Whatever sentence that you want commenters to use the checkbox for</label> Now that the checkbox

Using Multiple Permalink in WordPress

There time when you feel that the basic permalink settings of wordpress simply isn't enough when you want to make your url more meaningful and seo friendly. But how do we do this? There no much information on this out there as this is not something that all needs. Well, there is a very cool plugin out there that does exactly what you want. It's called   Advanced Permalinks The plugin provides advanced permalink options that allow you to: Have multiple permalink structures. Permalinks can be assigned to posts or ranges of posts 301 redirect old permalink structures (many structures are allowed) Category-specific permalinks. Posts in certain categories can be assigned a permalink structure No need to have a base to the category permalink! Change author permalinks Enable periods in permalinks - perfect for migrating old websit es.

Add new avatars to your wordpress and Say Good-Bye to Mystery Man

If you are like most of the other wordpress developers out there, then you might also had this problem with the default mystery man in wordpress. You also would wanted to change the deafualt avatar of your comments with something nice. It's not that hard. It's infact very easy. Just add this to your functions.php file within your theme folder. /** * add a default-gravatar to options */ if ( !function_exists('fb_addgravatar') ) { function fb_addgravatar( $avatar_defaults ) { $myavatar = get_bloginfo('template_directory') . '/images/avatar.gif'; $avatar_defaults[$myavatar] = 'people'; $myavatar2 = get_bloginfo('template_directory') . '/images/myavatar.png'; $avatar_defaults[$myavatar2] = 'wpengineer.com'; return $avatar_defaults; } add_filter( 'avatar_defaults', 'fb_addgravatar' ); } Why this? When you can have this! Happy coding! For any queries or suggestions give a comment below!

Inserting custom content after each post programmatically

There are time when you may want to automatically display a custom text below each of your posts. You can hard-code it, but why do it when there is better way to do so using a WordPress hook. Here’s how to do. Paste the following code into your functions.php and save the file. Custom content will be inserted below each of your posts. function add_post_content($content) { if(!is_feed() && !is_home()) { $content .= ' This article is copyright © '.date('Y').' '.bloginfo('name').' '; } return $content; } add_filter('the_content', 'add_post_content'); Related Articles: Inserts Posts Programmatically to WordPress Insert Categories & Tags Programmatically to WordPress

Get popular posts by comments counts

Big the biggest challenge of blogger is to retain readers in their blog. One of the best technique to do this showing the most popular posts or related posts on the site where user is bound to see it. Keep this just below the current post may increase the chance of user seeing it. The reason to choose popular ones is because there might be a reason for it to be popular. So the chance for the reader like it is more. Getting the Popular Post Just copy & paste this piece of code where you want the list to display: $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"); foreach($pop as $post) : ?> post_title; ?>

Add categories & tags to post programatically

There often time when you want to add categories or tags to a post from code. Wordpress codex has a good deal of resource on this but most of the time it's hard for the beginners to grasp. In this post we will try to crack this the easiest way. First let us create an array of categories id. Then we simply have to use the wp_set_object() function, which by default take 3 parameters: The post id. Array of categories to add to the post. taxonomy type (category in this example). $category_ids = array(4, 5, 6); wp_set_object_terms( $post_id, $category_ids, 'category'); Here is how tags can be added: Adding tags to a post is extremely easy as well. The only difference with the code to add categories is the taxonomy "post_tag" instead of "category". Related Posts: Inserting Posts Programatically to WordPress Insert Custom Content After Each Post

Inserting posts programmatically to worpress

There times when you want to add post from your code. For example for creating a custom post panel for your users in a classifieds site. But most of them don't know that this can be achieved very easily. Just paste the following code anywhere on WordPress theme files. If you want to test,But for testing pasting it in your  'functions.php ' file is recommended. global $user_ID; $new_post = array( 'post_title' => 'My New Post', 'post_content' => 'Lorem ipsum dolor sit amet...', 'post_status' => 'publish', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'post', 'post_category' => array(0) ); $post_id = wp_insert_post($new_post); That's all you have to do. Once executed, this code will insert a new post into WordPress database. Related Posts: Add Categories & Tags programmatically to WordPress Insert Custom

Custom Fields and Verve Meta Box Plugin

Ever wanted a better way to add custom fields? Wanted  to add really usable and good custom field meta box so that your client is happy? Well then Verve Meta Box plugin is your answer. It's very easy to use and best one out there for the purpose. Verve Meta Boxes  allows for creation of text, textarea, image, file, date, time, datetime, select, radio, and checkbox custom fields for posts and/or pages. A Meta Box added by the Plugin Values for custom fields are stored in wp_postmeta and can be accessed in templates through standard WordPress functions such as: the_meta, get_post_meta, get_post_custom, get_post_custom_values, etc. Once installed, it adds a configuration screen to your admin page which will be located under Tools in the left navigation. There you can create multiple meta boxes each with a set of user defined drag and drop sortable custom fields. The Admin Panel added by the Plugin Getting the values on to the template:  Getting the values submit

Change the WordPress Login page logo link without plugin.

Are you making a site for your client and frustrated with the login page logo linking to the WordPress site? Well you are not the only one. But there is a very easy way to change this behavior without any plugin. All you have to do is add the following line to your functions.php file within your theme folder. add_filter("login_headerurl","the_url"); function the_url($url) { return get_bloginfo('siteurl');//return the current wp blog url } This will link the logo to your own wordpress blog. If you don't know how to change the default WordPress logo with one of your logo, then follow this post that wonderfully illustrates the same. More On The Topic: The official wordpress documentation on this can be found here . If you have any queries please use the comment form below.

Customizing the wordpress login page without Plugin

Every one love to see their site totally branded. It does feel good when your users see the WordPress login page when they have to login, may be just to post a comment. Biggest problem come when you are developing for a client. Well though most of them don't know the solution is simple. You don't have to rely on any plugin just to do few modifications on the login page. You just have to add few lines to your functions.php file within your theme folder. "This is the final result, after adding the below code to functions.php" add_action("login_head", "my_login_head"); function my_login_head() { echo "<style>body.login #login h1 a { background: url('".get_bloginfo('template_url')."/styles/logo.gif') no-repeat scroll center top transparent; height: 49px;width: 229px; margin-left:auto;margin-right:auto; } body {background: url('".get_bloginfo('template_url')."/styles/bg.jpg') re

Adding Custom Post Type in Wordpress

WordPress is no more a blogging platform. People always tried to use it as CMS by applying their own techniques and ways. Wordpress kept on adding new feature in this direction in their releases. One of the most important addition to wordpress in this direction is Custom Post Types. One of the major requirement when using wordpress as a CMS. For example, say you are creating a Travel website listing restaurants & hotels. You would need 2 post types. Restaurant Hotel Ofcourse people used to do this by using categories and all. But that was not a good solution when developing for a client. Now you could add custom post type by adding this small piece of code to your functions.php file within your theme folder: //Add restaurant function post_type_restaurant() { register_post_type( 'restaurant', array( 'label' => __('Restaurant'), 'public' => true, 'show_ui' => true ) );

Using Featured Image in WordPress

Today there are innumerable blogs on any topic you would choose. If you are a blogger your main priority would be to make your blog, stand out! Make it more attractive and tempt people to read what you right. One of the most important technique that major blogs use is setting a featured image for each post. This can be achieved very easily as it 's there in-built in wordpress. But you have to enable it in functions.php file within your theme folder. Here is how you do that: add_theme_support( 'post-thumbnails' ); Paste this within your functions.php file. Additionally you can specify which should have this feature in an array like this: // Add it for posts add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for pages add_theme_support( 'post-thumbnails', array( 'page' ) ); You also additional control over this, you explicitly decide the dimension or hard crop the thumbnails etc. The dimension can be set like this: //the scale