Saturday, September 1, 2012

How To Create A Custom Page Template In WordPress

To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.

That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:
<?php /* Template Name: Cover Page */ ?>
<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>


<?php if (is_page_template('cover_page.php') ) 
{ ?>    <p>Apples</p>    <?php } 
else { ?>    <p>Oranges</p>    <?php } ?>

Tuesday, August 28, 2012

How to automatically add rel=”lightbox” to all images embedded in a post

The well known jQuery plugin Lightbox is a very simple way to open images in fancy full-screen boxes. It is very easy to use, but you have to add a rel=”lightbox” attribute to each image you want to open in a lightbox. Here’s a cool code snippet to automatically add the rel=”lightbox” attribute to all images embedded in your posts.
 
Paste the following code snippet in your functions.php file. 
Once done, a rel="lightbox" attribute will be automatically 
added to all images embedded in a post.
 
 function my_addlightboxrel($content) {   
      global $post;
      $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";         
  $replacement = '<a$1href=$2$3.$4$5 rel="lightbox" 
                title="'.$post->post_title.'"$6>';        
  $content = preg_replace($pattern, $replacement, $content);       
  return $content;
  }
add_filter('the_content', 'my_addlightboxrel');

How to easily add shortcuts to WordPress toolbar

As with many things, WordPress makes it easy to customize the Toolbar, using the add_node() functions. In this recipe, I’m going to show you how to add a shortcut to WordPress toolbar.

function custom_toolbar_link($wp_admin_bar) {
$args = array( 'id' => Help,
'title' => 'Help',
'href' => 'http://h20bikash.blogspot.com/',
'meta' => array( 'class' =>Help,
'title' => 'Help' ) );
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'custom_toolbar_link', 999);

How to add .pdf support to the WordPress media manager

By default, the built-in WordPress media manager allows you to filter media by three types: images, audio and video. But if you work a lot with .pdf files, you may need to add an option to filter .pdf files from the media manager. Here is a simple code snippet to do it.

Paste this code into your functions.php file. Save the file, and you're done.
 
function modify_post_mime_types( $post_mime_types ) {
// select the mime type, here: 'application/pdf'
// then we define an array with the label values
$post_mime_types['application/pdf'] = array( __( 'PDFs' ), __( 'Manage PDFs' ), _n_noop( 'PDF (%s)', 'PDFs (%s)' ) );
// then we return the $post_mime_types variable
return $post_mime_types;
} // Add Filter Hook
add_filter( 'post_mime_types', 'modify_post_mime_types' );

How to automatically empty trash on a daily basis

Simply open your wp-config.php file (Located at the root of your WordPress install) and add the following line of code:

define('EMPTY_TRASH_DAYS', 1);

How to remove the url field from WordPress comment form

In some cases, you may not need or want that people who comment your posts can leave their website url. Here is a simple code snippet to remove the url field from WordPress comment form.

Paste the code below into your functions.php file. Once saved, the url field will be removed from your comment form.
 
function remove_comment_fields($fields) {  
    unset($fields['url']); 
     return $fields;  
}
  add_filter('comment_form_default_fields','remove_comment_fields');

Monday, August 13, 2012

Complete flexible Project Task Management System


This WordPress plugin is a complete flexible Project Task Management System. It's a very easy to use, but yet a powerful plugin.