Sunday, December 4, 2011

Be Like a Pro with These Simple WordPress Tricks


Be Like a Pro with These Simple WordPress Tricks

Blogging has become a trend that when you search for something on the net, most probably the sites you’ll see are blog sites. Many people now run their own blog site either as a hobby or to earn money online. For beginners, I’ll show you simple tricks that would help you use WordPress like a pro.        

1.       Add a PayPal Donation link. 

Below is a code for your PayPal donation link. Copy and paste this into your WordPress template’s functions.php file. Remember to replace the default ‘account’ with your PayPal email address. After you’re through pasting and saving it, you will now be able to display a donation link on your site.

function cwc_donate_shortcode( $atts ) {
extract(shortcode_atts(array(
'text' => 'Make a donation',
'account' => 'REPLACE THIS WITH YOUR PAYPAL EMAIL',
'for' => '',    ), $atts));
global $post;
if (!$for) $for = str_replace(" ","+",$post->post_title);
    return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation+for+'.$for.'">'.$text.'</a>';
}
add_shortcode('donate', 'cwc_donate_shortcode');
                                                        
2.       Shortcodes for template widget

There are plugins that come in simple shortcodes so we can use them in the widgets area. Here’s a code that you can add to your template’s functions.php file to enable a shortcode support there.
add_filter( 'widget_text', 'do_shortcode' );
If you want to display the shortcode [donate] anywhere in template files, add this code below:               
echo do_shortcode('[donate]');

3.       Make Members-Only content 

You can also create members-only content with this shortcode below if you want to hide your blog content to the public or guest users.  Add this somewhere in your template’s functions.php and save.

function member_only_check( $atts, $content = null ) {
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return '';
}
add_shortcode( 'onlymember', 'member_only_check' );

This is a sample of a members-only content:
[onlymember]This content is available to registered users only.[/onlymember]

4.       Hide Page from Navigation

Aside from creating a member-only content, you can also hide any page from the navigation bar. Here is a code that would hide some pages.
wp_page_menu('exclude=5,9,23');
On the example above, we excluded id pages 5,9 and 23 to make it invisible. To find the page ID, simply go to Dashboard > All Pages. Hover your mouse on any of your posts and you can view the ID at the bottom of browser that shows the link.


About the Author: MARVIN BEA is a blogger, webmaster and musician from the Philippines. His interests include arts, photography, travel, fitness and health. He loves to learn web design and he is also a resource writer for Blogfreakz

No comments:

Post a Comment