Imagine if you knew how to code wordpress themes and designs then you wouldn’t have to spend massive amount of money on purchasing it. Usually, I work on the themes on most of my blogs. I enjoy tweaking all the time because it is very essential for your blog.
I am sure most of you would love to discover some cool wordpress hacks and I hope you enjoy this article. If you are not a pro then I would suggest that you try these on a new wordpress installation.
How to display Adsense when you Only want to
To use this trick, you need a self hosted wordpress and an adsense account of course.
Insert the following code into your function.php file. All or majority of the themes come with a function.php file.
|
function showads() {
return ‘<script type=”text/javascript”><!– google_ad_client = “pub-xxxxxxxxxxxxxxx”; google_ad_slot = “4668915978″; google_ad_width = 468; google_ad_height = 60; //–> </script> <script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”> </script>’; } |
Once you are done, you will be able to insert adsense whenever and wherever you want it in your post. To do that, simply paste the following code in your post (make sure you are in the HTML mode)
| [adsense] |
How to Show Parent Page Title regardless of what Subpage you are on
Now this is only for the people who are using wordpress as their content management system. Simply paste the code anywhere on your theme files and it will display the parent page title.
|
<?php
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
} else {
wp_title(”);
}
?>
<?phpif($post->post_parent) { $parent_title = get_the_title($post->post_parent); echo $parent_title;} else { wp_title(”);}?> |
How to Automatically insert Author Bio on each post
This is best used on a blog owned by multiple authors. If you write a post, you would definitely want to take the credit for it and thus display your bio on the post. If you have guest bloggers then this is a great method to give them credit for their contribution
Simply insert the following code into your functions.php file and it is good to go. Author bio will be automatically displayed after each post.
| function get_author_bio ($content=”){ global $post; $post_author_name=get_the_author_meta(“display_name”); $post_author_description=get_the_author_meta(“description”); $html=”<div class=’clearfix’ id=’about_author’>\n”; $html.=”<img width=’80′ height=’80′ class=’avatar’ src=’http://www.gravatar.com/avatar.php?gravatar_id=”.md5(get_the_author_email()). “&default=”.urlencode($GLOBALS['defaultgravatar']).”&size=80&r=PG’ alt=’PG’/>\n”; $html.=”<div class=’author_text’>\n”; } |
Speed up Your Blog’s Loading Speed
There are so many web hosting that it is difficult to find out which one is best for blogging. Your host might be slow and it can annoy your readers. Do you know that you can lose tons of readers if your blog lags or loads really slow.
You need zlib php extension enabled by your hosting provider. Once that is taken care of, simply place the following code in your header (above the DOCTYPE). Save the file and enjoy the speed.
|
<?php
ini_set(‘zlib.output_compression’, ‘On’);
ini_set(‘zlib.output_compression_level’, ‘1′);
?>
|
How to Display registered users comment count on your Blog
If your blog has a lot of registered users, then you may want to display the number of comments posted by them. Paste the code below wherever you want to display the count.
| <?php
global $wpdb; |
How to Create a Tweetmeme “Retweet” shortcode
Without any doubt, twitter is one of the best ways to get quality traffic to your blog. Of course, you can use several plugins to display this but if you want to do it the pro way then you might want to consider this. The code will display how many times your post has been retweeted.
Just paste the code below into your functions.php file and bingo!
| function tweetmeme(){
return ‘<div class=”tweetmeme”><script type=”text/javascript” src=”http://tweetmeme.com/i/scripts/button.js”></script></div>’; } add_shortcode(‘tweet’, ‘tweetmeme’); |
Once the file has been saved, you can display the “retweet” button almost anywhere on your posts. When writing a post, simply insert the below code (make sure you are in html mode when inserting the code).
| [tweet] |
When you publish the post, the shortcode [tweet] will be replaced by the TweetMeme button.
How to get tags related to category
This is one of my favorite hack and I am sure you will love it too. This will allow you to get tags related to one or more specific category.
Paste the code in your functions.php file
| function get_category_tags($args) {
global $wpdb; } |
Once you have done that, use the below code in your theme
| $args = array(‘categories’ => ‘12,13,14′); $tags = get_category_tags($args); |
How to Get all Custom fields from a Page or a Post
This code will allow you to get all the custom fields from a specific post or page. Paste the code below in your functions.php file
| function all_my_customs($id = 0){ //if we want to run this function on a page of our choosing them the next section is skipped. //if not it grabs the ID of the current page and uses it from now on. if ($id == 0) : global $wp_query; //knocks the first 3 elements off the array as they are WP entries and i dont want them. endforeach; } |
You can use the function with the following code
| $result = all_my_customs(); echo $result['my_meta_key']; |
I hope you find this useful. Make sure you know your stuff well before applying all these. I have pretty good knowledge of photoshop as well as coding to some extent so if you need any assistance just reply through comments and i will try to get back to you.
Check Out Related Posts:
- How To Display Feedburner Subscriber Count In Text With A Script
- 10 Free Plugins To Make Your WordPress Blog Super Fast
- Top WordPress Optimization Tips
- An Unexpected HTTP Error occured during the API request -FIXED
- The Future is Here- WordPress 2.9 is Available for Download












