Most Wanted WordPress Hacks: 11 New Requests (2)
This is the second article in our new three-part WordPress series. I want to share with you some hacks that i found to be very useful when i was working on the redesign of Noupe and during the design of my other site Devsnippets. Throughout this article, we’ll be focus on many WordPress Theme hacks, ideas, tips and useful tutorials you need to have ready in hand when developing WordPress websites.
You can check out the first article in this series here.
You might also be interested to check out our previous four part series, "Powerful guide to master Your WordPress Theme
So let's get started and don't forget to subscribe to our RSS-Feed and visit my twitter page : nourayehia if you want to follow to keep track on our last post in this series.
Pulling that information dynamically is slightly trickier, so Darren Hoyt provided a simplified version of Ben's code which must be included outside of the loop
Wordpress Hotlink protection plugin is a useful plugin that avoid being hotlink by spam blogs. It doesn’t protect the images in the feed. So hotlinking the image urls from the feed is possible.
This detailed tutorial on creating custom write panels for the WordPress Write Post page using "add_meta_box()"
This nice tutorial by firewalker will show you how to install google search code in your Wordpress SEARCH FORM and SEARCH RESULTS pages that can be found in your current theme folder.
1.Loading Javascript Libraries in Wordpress generated page
Load jQuery into WordPress generated pages, the wp_enqueue_script function can be used in plugins as well.<?php wp_enqueue_script('jquery'); ?>Add and load a new script that depends on jQuery (this will also cause it to load jQuery into the page as well):
<?php wp_enqueue_script('newscript','/wp-content/plugins/someplugin/js/newscript.js',array('jquery'),'1.0' ); ?>
2. Protecting your email From the bad guys
If your e-mail address is publicly available into your generated pages, it may be vulnerable to e-mail harvesters that scan pages on the Internet for e-mail addresses to collect and send unsolicited e-mail. You can use a free online encoder to encode your email address or use the antispambot() function built into WordPress:<?php echo antispambot(get_the_author_email()); ?>
3. Exclude Categories from RSS Feeds
Sometimes you just want to exclude categories like "News" or "Sideblog" from your RSS feed since most of the subscribers aren’t interested to read it. All you have to do is change the url of your feed in your feedburner to something like this: https://www.noupe.com/feed?cat=-79. Where "79" is the ID of the category you want to exclude. You can find the ID of any category by going to your Admin panel > Manage > Categories where you’ll see the IDs of all your categories. Another way to exclude a category from your RSS feed if you are not using feedburner, is to add a custom function in your "functions.php" file in your current theme folder:function ExcludeCategory($query) { if ($query->is_feed) { $query->set('cat','-79,-26'); } return $query; } add_filter('pre_get_posts','ExcludeCategory');This code will execlude categories ID="79" and ID="26" from your feed. Thanks to Jangro's tip
4. Displaying Related Category and Author Content in Wordpress
Supporting your posts with related content is valuable to readers who want additional context and to bloggers who want a stickier site.Pulling that information dynamically is slightly trickier, so Darren Hoyt provided a simplified version of Ben's code which must be included outside of the loop
post->post_author; $tempQuery = $wp_query; $currentId = $post->ID; // related author posts $newQuery = "posts_per_page=5&author=" . $authorPosts; query_posts( $newQuery ); $authorPosts = ""; $count = 0; if (have_posts()) { while (have_posts()) { $count++; the_post(); if( $count<4 && $currentId!=$post->ID) { $count++; $authorPosts .= '
'; } } } // related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "posts_per_page=5&cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count = 0; if (have_posts()) { while (have_posts()) { the_post(); if( $count<4 && $currentId!=$post->ID) { $count++; $categoryPosts .= '
'; } } } $wp_query = $tempQuery; ?>Then inside the loop, call the functions like this:
More from this category
More from this author
5. Placing Images with the Posts
Without Custom Fields you wouldn't see all the magic going around with those amazing Premium WordPress Themes, you need to know how to use them efficiently to associate thumbnail images with posts. Essentially, your posts are queried via the Loop, and if the custom field Key (”Image”) has a value, that value is inserted into your tag like this:" alt="" />The code must be inside The Loop wherever you put it. Or You can just use Worpdress’s image upload tool rather than FTP, right from your Admin Write panel, so that you can configure your own "upload" folder and get the URL of your uploaded image to paste into the Custom Fields box.
6. Protect your bandwidth from hotlinking
There are different ways you can use to protect your server from bandwidth thieves who try to steal our bandwidth by hotlinking images belonging to our blogs on their spam blogs. One of the common ways is to edit your .htaccess file located in your WordPress root folder and add this code:RewriteEngine On #Replace ?mysite\.com/ with your site url RewriteCond %{HTTP_REFERER} !^http://(. \.)?mysite\.com/ [NC] RewriteCond %{HTTP_REFERER} !^$ #Replace /images/no-hotlink.jpg with your "no hotlink allowed" image url RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/no-hotlink.jpg [L]If you managed to add this code to your .htaccess file and you want to see if it works, try this nice tool and see what alternative image bandwidth thieves will display in their blog. The only issue with this solution is that your images won't be visible for RSS Readers. You can add popular RSS reader's url in your .htaccess file.
Wordpress Hotlink protection plugin is a useful plugin that avoid being hotlink by spam blogs. It doesn’t protect the images in the feed. So hotlinking the image urls from the feed is possible.
7. Creating Custom Write Panels in WordPress
If you were to put together a Custom Write Panel for your blog, you can use "Custom Write options" to easily add any unique data to your post. Custom write panels are most useful for customized installations of WordPress and could be used to add many different types of information into a post both easily and quickly using "add_meta_box()".This detailed tutorial on creating custom write panels for the WordPress Write Post page using "add_meta_box()"
8. Wordpress Search as Custom Google Search Without Additional Page or Post
Want to modify the default Wordpress Search to be seen as Custom Google Search without using any plugins, additional post, or page. It’s simply replacing Wordpress Search with Custom Google Search. The first thing to learn is to create Custom Google Search account of your own. Maki from Doshdosh.com already created the tutorial on embedding Custom Google Search in his website.This nice tutorial by firewalker will show you how to install google search code in your Wordpress SEARCH FORM and SEARCH RESULTS pages that can be found in your current theme folder.
9. Replacing WordPress content with an excerpt without editing theme files
WordPress function <?php the_content(); ?> is used to retrieve all post content. Let%u2019s say you want to show excerpts instead of the entire post, we could easily just change <?php the_content(); ?> to <?php the_excerpt(); ?>. But, what if you don%u2019t want to edit the core files at all and want to be able to upgrade your theme without my modifications being broken. Justintadlock has the solution: WordPress filters In your child theme’s functions.php file, add this bit of PHP to tell WP that we want to filter the_content() with our own function.:// Add filter to the_content add_filter('the_content', 'my_excerpts');
10. Provide RSS Feed for Category
If you want to provide an RSS Feed per category, so your readers will be able to only read what interests them. Let's say you want to provide RSS Feed for your "news" category. The category url is:https://www.noupe.com/category/newsTo get the rss feed of the "news" category, simply just add /feed at the end of the ur. Thanks to WPRecipes for this nice tip:
https://www.noupe.com/category/news/feedTo create a category rss feed, simply paste the following code:
<a href="<?php echo get_the_category().'/feed'; ?>"><?php echo get_the_category().' rss feed'; ?></a>
11. Exclude pages from search results
If you want to exclude pages from appearing in your WordPress search results, all you have to do is to add a filter in your functions.php found in your current theme folder:// Exclude pages from search results function SearchFilter($query) { if ($query->is_search) { $query->set('cat','20,34,8'); } return $query; } add_filter('pre_get_posts','SearchFilter');Where the posts category IDs (’20,34,8'?) are those you want to exclude from your search results.
Very usefull
thanks …. Those are really usefull tips
nice and really informative tips
very coool hacks, thank you very much for sharing
Just so good ! Thank you
nice share. thanks for information.
absolutely usefull !!
Excellent …no words to explain the importance of this article…