10+ WordPress Tips and Tutorials that Will Make You a Pro
Astra WordPress Theme

10+ WordPress Tips and Tutorials that Will Make You a Pro


Why wordpress is one of the most popular CMS and blogging platform around? I think it because wordpress is free, customizable and have a great support by community or other developers. And as wordpress users, we should keep updated with the new development, tips and tricks shared by other developer.

In this article we are going to share very useful wordpress tutorial. We hope this post will help you in solving problems on your wordpress site and as a source of inspiration to develop your wordpress site.

1. Display Messages For Logged In Users

If you have users on your WordPress blog, you can choose to display messages/stuff only for them, or vice versa, you can refer to this simple one step tutorial.

Place the below code in functions.php file:

[php]
if ( is_user_logged_in() ) {
echo ‘Welcome, registered user!’;
} else {
echo ‘Welcome, visitor!’;
};
[/php]

2. How To Increase Default Number Of Custom Fields From 30

If you are a theme developer, you might know that WordPress by default limit you to add up to 30 custom fields. If you want to increase the limit, you can refer to this simple one step tutorial.

Add the below code in functions.php

[php]
add_filter( ‘postmeta_form_limit’ , ‘customfield_limit_increase’ );
function customfield_limit_increase( $limit ) {
$limit = 100;
return $limit;
}
[/php]

3. How To Show All Posts From A Category

If you want to display all the articles of a particular category on a page template or at any supported place, this simple tutorial will help you.

[php]
$displayposts = new WP_Query();

//get posts from your news category
$displayposts->query(‘cat=5’);

while ($displayposts->have_posts()) : $displayposts->the_post();

the_content(‘read more…’);
edit_post_link(‘edit’, ”, ”);

endwhile;
[/php]

4. How To Change WordPress Login logo

If you want to change the logo you see where you enter the login credentials in WordPress, this simple tutorial will help you achieve that. This also helps as a brand building, if you want to, especially if you have multiple authors.

Place the below code in functions.php file:

[php]
function custom_login_logo() {
echo ‘<style type="text/css">
h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/login_logo.png) !important; }
</style>’;
}
add_action(‘login_head’, ‘custom_login_logo’);
[/php]

5. How To Change Login Logo URL In WordPress

Ever noticed and wanted to change the link you see on the login page of your WordPress Admin panel? This simple tutorial will help you achieve it.

Place the below code in functions.php file:

[php]
<?php
add_action( ‘login_headerurl’, ‘my_custom_login_url’ );
function my_custom_login_url() {
return ‘http://www.example.com’;
}
?>
[/php]

6. How to Specify Autosave Interval in WordPress

While you are working in a post/article, you must have noticed that WordPress autosaves the article for you, so in case you get disconnected you don’t loose your article. Also it can be annoying for some folks, if its doing it too often. Though you can change the autosave time interval with this simple trick.

Place the below in your wp-config.php file:

[php]
# Autosave interval set to 300 seconds #
define(‘AUTOSAVE_INTERVAL’, 300);
[/php]

7. Change The Excerpt Length

If you ever wanted to change the Excerpt text length, whether to increase it or decrease it, this one step tutorial will help you much.

Place the below code in functions.php file:

[php]
function new_excerpt_length($length) {
return 30;
}
add_filter(‘excerpt_length’, ‘new_excerpt_length’);
[/php]

8. Disable WordPress Search

For whatever reason the time may come when you need to disable WordPress’ in built search function, your project might not call for it or you might want to change it out for Google Search for example.

To do this is relatively easy, In functions.php  add the following:

[php]
function no_search_please($query, $error = true) {

if (is_search()) {
$query->is_search = false;
$query->query_vars[s] = false;
$query->query[s] = false;

if ($error == true)
$query->is_404 = true;
}
}

if (!is_admin()) {
add_action(‘parse_query’, ‘no_search_please’);
add_filter(‘get_search_form’, create_function(‘$a’, "return null;"));
}
[/php]

And that’s it, your WordPress install now has no search function and even if someone tries to search in the address bar (eg: http://yoursite.com/?s=search-term) they will get a 404 error page.

9. Adding Paypal Donation link

Many of us consider plugin as an easy go thing but that sometimes affects your site opening speed. Also searching suitable and easy to use needs bit more of your time. This doesn’t mean you never use plugins, you should! but try to make them to minimum. A better alternative solution is using short codes.

Paste the below code in functions.php file of your template and don’t forget to replace the default ‘account’ with your paypal email address. Once done, you will be able to show donation link with-in post calling shortcode [donate]

[php]
function cwc_donate_shortcode( $atts ) {
extract(shortcode_atts(array(
‘text’ => ‘Make a donation’,
‘account’ => ‘REPLACE ME 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’);
[/php]

10. Integrate some Adsense Ads

Want to output some adsense ads in posts? Try this:

Paste the below code in functions.php file of your template. Once done, you will be able to show Adsense Ads with-in post. Remember to replace the adsense code with your own from google. Now you can output an ad simply using [adsense].

[php]
function adsense_shortcode( $atts ) {
extract(shortcode_atts(array(
‘format’ => ‘1’,
), $atts));

switch ($format) {
case 1 :
$ad = ‘<script type="text/javascript"><!–
google_ad_client = "pub-6928386133078955";
/* 234×60, created 16/09/08 */
google_ad_slot = "0834408702";
google_ad_width = 234;
google_ad_height = 60;
//–>
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>’;
break;
}
return $ad;
}
add_shortcode(‘adsense’, ‘adsense_shortcode’);
[/php]

11. Calling a Short Code in template file or widget

Sometimes a plugin comes up shortcode support that we can use with-in the post body easily. There may be need to use them in widgets area or in a template file. So here’s a widget solution first. Add the below code into functions.php file of your template to enable support for short codes there!

[php]
add_filter( ‘widget_text’, ‘do_shortcode’ );
[/php]

What if we want to use that short code in template files, Here a solution to use them anywhere in template files as well. I’m supposing that you want to execute shortcode [donate] at somewhere in template file. Below is the code to go with with-in the PHP tags:

[php]
echo do_shortcode(‘[donate]’);
[/php]

12. Hide/Exclude a Page or a post from Navigation

You can hide any page from navigation bar. i’m assuming that you are using wp_page_menu. To exclude some page from being shown, just pass the args like below:

[php]
wp_page_menu(‘exclude=5,9,23’);
[/php]

Here we have excluded three pages with id 5, id 9 and id 23. To know the id of page, goto dashboard > All pages. Point mouse over any post and you will see the id at the bottom of browser showing link.

Give WordPress page’s excerpts

A handy snippet to have to hand, for WordPress 3.0+:

[php]
function enable_page_excerpt() {
add_post_type_support( ‘page’, ‘excerpt’ );
}
add_action(‘init’, ‘enable_page_excerpt’);
[/php]

Add that to your theme’s functions.php file and your good; pages will now show an excerpt panel.

Written by
Suresh Patel
Join the discussion

6 comments

Let’s get social

Web design blog for professionals with topics focusing on useful design techniques, design best practices and design inspiration. Subscribe for updates!

15585

JOIN OUR GROWING LIST OF SUBSCRIBERS!

Following our blog is a great way to make sure that you are up to date on the latest and greatest Freebies and WordPress news.

15856