Category Archives: WordPress
How To Restrict Other Servers From Accessing Your Files ?
If your site stores popular image files then for reducing bandwidth usage you can use this Apache hack for denying servers to access your files. Open your sites .htaccess file for editing and add the following code:
<FilesMatch “.(gif|jpe?g)$”>
SetEnvIf Referer “^http://([^/]*.)?mydomain.com/” request_ok = 1
Order Allow, Deny
Allow from env=request_ok
</FilesMatch>
This restricts other domains form accessing all GIF or JPG files in your website.
WordPress Hack For Adding Signature After Posts Content
Open your theme’s function.php and add the following code. Remember changing text after equal sign with your own.
function custom_content_after_post($content){
if (is_single()) {
$content .= ‘<p>Load Your Content Here</p><img src=”‘. get_template_directory() .’/images/signature.png” alt=”Your Name” />’;
}
return $content;
}
add_filter( “the_content”, “custom_content_after_post” );
You may also use WordPress Signature Plugin for doing so. It allows WP users to put signatures below every post. After installing and activating it you can easily access it by navigating to WP-Admin Dashboard >> Tools >> WPSignature.
Become Google’s Verified Author For Your WordPress Blog
After getting Google’s verified authorship you will be seeing your blog post search results with the screen shot of your Google Plus Profile Image. As show below:
For doing this in your blog results, follow these steps
Open your theme’s header.php file and add the following given code block in head section –
<link rel=”author” href=”https://plus.google.com/107466614529996508363/posts” />
Remember:
- Change the profile URL with your Google Plus Profile URL in the above given code block.
- Head section is between <head> and </head> tag so add the given code in between these tags.
Now open your theme’s function.php file and the following action at last:
add_action(‘wp_head’, ‘add_google_rel_author’);
function add_google_rel_author() {
echo ‘<link rel=”author” href=”https://plus.google.com/107466614529996508363/posts” />’;
}
- Visit your Google+ Profile.
- Click Edit and make your +1s pubic.
- Scroll down to contributors section.
- Under the heading “Contributor to” add your blog’s address.
That’s all. Next Google’s re-crawl to your blog pages will start showing your face in Google search results. So wait for it. You can reduce this time by writing a new blog post.
Disable Comments On WordPress Media Attachments
Using WP Plugin
Download and activate Disable Comments plugin. Using this plugin admins can easily disable comments site wide or according to post type. After installation it can be accessed from settings menu of admin area dashboard.
Using WP Hack
Add this code in your theme’s function.php file:
function filter_media_comment_status( $open, $post_id ) {
$post = get_post( $post_id );
if( $post->post_type == ‘attachment’ ) {
return false;
}
return $open;
}
add_filter( ‘comments_open’, ‘filter_media_comment_status’, 10 , 2 );
How To Protect wp-config.php And .htaccess Files In WordPress ?
You can block access to your site’s wp-config file from browser by adding following code in your .htaccess file:
# Block access to wp-config
<files wp-config.php>
order allow,deny
deny from all
</files>
For blocking access to your .htaccess file add this code inside your .htaccess file:
# Block access to htaccess
<files .htaccess>
order allow,deny
deny from all
</files>
Note:.htaccess file is present in your site’s root at the same place where you find wp-config file.
Protecting Your WordPress Admin From Hacks
You may use this trick for adding an additional layer of security on your WordPress site so that your site don’t get compromised and hacked:
- Open your cPanel.
- From Security section click Password Protect Directories.
- Now on the Pop Up. Select root then from your WordPress installation select wp-admin.
- Check Password protect this directory.
- Create a user for that directory; there is an option below the check box. That’s it..
Now anytime you visit wp-admin directory you should notice an authentication box asking you for the username and password for authentication.
Sometimes it may show some errors depending on how your server is configured. Don’t worry, just ask me here about the problem(if you face one).
Monitor, Manage And Backup All Of Your WordPress Sites At Once From A Single Place
Using WP Remote you easily monitor, update and backup all of your WordPress sites at the same time from a single place. It communicates with your WordPress site using API like Akismet so there is no need of providing username and password and it is completely free to use.
Features:
Know WP Remote Latest Enhancements
- It can track all of your sites.
- No limitation to number of sites you add.
- It can update WP-Core, all plugins and themes.
- Check WP Remote Security policy here.
WP-Hack For Adding Google+ Page Badge ‘Add to Circles’ In Your WordPress Blog
Add this code in your theme’s header.php file’s head section:
<link href=”https://plus.google.com/PageID” rel=”publisher” /><script type=”text/javascript”>
(function()
{var po = document.createElement(“script”);
po.type = “text/javascript”; po.async = true;po.src = “https://apis.google.com/js/plusone.js”;
var s = document.getElementsByTagName(“script”)[0];
s.parentNode.insertBefore(po, s);
})();</script>
Replace PageID (in bold text of above code block) with your Google+ Page ID.
Now visit your blog’s wp-admin (Dashboard) >> Appearance >>Widgets and drag text widget to your sidebar.
Paste following code inside your text widget (replacing PageID) :
<g:plus href=”https://plus.google.com/PageID” size=”badge”></g:plus>
For smaller badge use:
<g:plus href=”https://plus.google.com/PageID” size=”smallbadge”></g:plus>
Note: You can get your Google Plus Page ID by visiting your page’s profile and copying the number before /posts or /about in URL.
Function For Defining Default Post Thumbnail In WordPress
Open your theme’s function.php file and add the given function editing the thumbnail image URL (given in bold text) with your own image URL.
add_action( ‘save_post’, ‘wptuts_save_thumbnail’ );
function wptuts_save_thumbnail( $post_id ) {
$post_thumbnail = get_post_meta( $post_id, $key = ‘_thumbnail_id’, $single = true );
if ( !wp_is_post_revision( $post_id ) ) {
if ( empty( $post_thumbnail ) ) {
update_post_meta( $post_id, $meta_key = ‘_thumbnail_id’, $meta_value = ‘https://sangkrit.net/thumbnail.jpg’ );
}
}
}
How To Edit WordPress ‘Posts’ Label ?
You can edit WordPress post label to something Else. For example if you want to edit Posts (label) to Article so that anytime you or any other member visit you wp-admin (dashboard) he can see Article as a label on sidebar menu not posts (which is by default).
For doing this, open your theme’s function.php file and add the following code:
add_filter(‘gettext’, ‘change_post_to_article’);
add_filter(‘ngettext’, ‘change_post_to_article’);
function change_post_to_article($translated) {
$translated = str_ireplace(‘Post’, ‘Article’, $translated);
return $translated;
}
How To Add Custom User Roles In WordPress ?
Suppose you need to create a new custom post type, may be NEWS. So that you can allow you subscribers to post NEWS on your website. In the given example we will be creating a custom user role for NEWS and the users allotted this role would only be managing only NEWS section from WP-Admin (Dashboard).
Open your theme’s function.php file: site root >> wp-content >>themes >> function.php and add the given code block:
add_role( ‘news_user’, ‘News User’, array( ‘news’ ) );
This function generates new custom user role which can only manage
news section from Dashboard.
Although you may add some more function for new custom user role.
New custom user role can also be removed from WordPress by using the following function in your theme’s function.php file:
remove_role( ‘news_user’ );
From WordPress Function $wp_roles also you can add and remove custom user roles as show below:
global $wp_roles;
$wp_roles->add_cap( ‘news_user’, ‘manage_category’ );
$wp_roles->remove_cap( ‘news_user’, ‘view_post’ );
WordPress Hack To Set A Custom Default Avatar
- Create a new custom Avatar. It should be 60px*60px PNG format.
- Name it custom-avatar.png.
- Upload this avatar image in your /wp-content/themes/yourtheme/images directory
- Open you theme’s functions.php file
- Copy the following given code and paste it in your functions.php file:
if ( !function_exists(‘custom_gravatars’) ) {
function custom_gravatars( $avatar_defaults ) {
$myavatar = get_template_directory_uri() . ‘/images/custom-avatar.png’;
$avatar_defaults[$myavatar] = ‘people’;
return $avatar_defaults;
}
add_filter( ‘avatar_defaults’, ‘custom_gravatars’ );
}
- Open your Admin Section (Dashboard)
- Visit Settings >> Reading section and select your newly uploaded avatar as default.
How To Display WordPress Featured Posts And Pages ?
Featured Page Widget
From this widget you can feature pages on your sidebar using an excerpt of the page and a text or image link to the page. Click here to know more features.
Download WordPress Featured Page Widget
Installation:
- Install and Activate the plugin
- Configure options from Dashboard >> Settings panel.
- Add widgets to your sidebar.
Featured Post Widget
It is a customizable multiwidget, that displays a single post in the widget area. You can decide, whether or not the post thumbnail is displayed, whether the post title is above or beneath the thumbnail and a couple of more things. You can style the widget individually.
Download WordPress Featured Post Widget
Installation:
- Install and Activate the plugin.
- Add and customize the widget.
Embeding SWF In WordPress Posts
You can easily embed SWF file inside your WordPress post either by using a plugin or by using WP hack.
Using WordPress Plugin:
- Open your Dasboard
- Visit Plugins >> Add New and Search for Easy Flash Embed plugin.
- Install and Activate it.
Use the following shortcode for embedding your SWF file in your posts:
[swf src=”http://www.example.com/file.swf” width=200 height=50]
Note: In the given shortcode replace the link address to your own SWF file address and adjust the height and width as per your needs.
Using WordPress Hack:
Here is your WP Hack. Use following code for embedding Flash directly into WordPress pages and posts etc:
<object id=”flashcontent”
classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″
width=”550px”
height=”400px”>
<param name=”movie” value=”movie.swf” />
<!–[if !IE]>–>
<object type=”application/x-shockwave-flash”
data=”movie.swf”
width=”550px”
height=”400px”>
<!–<![endif]–>
<p>
Text written here will only be visible if the SWF fails to load.
</p>
<!–[if !IE]>–>
</object>
<!–<![endif]–>
</object>
Embedding SoundCloud In Your WordPress Posts
You can embed SoundCloud in your WordPress posts using WordPress feature oEmbed. It supports auto embedding until your URL breaks the line. WP oEmbed library supports Twitter, YouTube and many other popular services. SoundCloud is not yet supported by WordPress but still you have it by using oEmbed with the help of this function: wp_oembed_add_provider()
Adding oEmbed for SoundCloud in WordPress:
Open your theme’s function.php file and add the following code:
function add_oembed_soundcloud(){
wp_oembed_add_provider( ‘http://soundcloud.com/*’, ‘http://soundcloud.com/oembed’ );
}
add_action(‘init’,’add_oembed_soundcloud’);
All done. Now you can simply paste SoundCloud URL on separate line and let oEmbed do auto-embedding.
Using WordPress Plugin:
You may also use this WordPress Plugin SoundCloud is Gold.
If you are running your blog on WordPress.Com then you may use the shortcode available for all WordPress.Com users because Sound Cloud is officially supported by WordPress.Com.
If you have a self hosted blog then you may use JetPack plugin and enable option for shortcode embeds. After doing this you can easily use the shortcode as shown here:
WordPress Hack To Remove Certain Categories From Being Displayed
This hack is useful for those who like to display certain category to chosen or registered users only. Add the following given code inside The Loop and choose the category (number) which you wish to remove from the display.
<?php
if ( have_posts() ) : query_posts($query_string .’&cat=-1,-2′); while ( have_posts() ) : the_post();
?>
Creating And Managing Tables Inside WordPress Posts
WordPress Visual Editor don’t provides you the option to create table inside your post content. Hence to create a table in WordPress you need to know HTML. Reading this tutorial you can create tables in your WordPress posts even if your are not good in HTML.
- Go to plugins menu.
- Install Easy Table Plugin and Actvate it.
- Move to Dashboard >> Settings >> Easy Table.
Here you will get various table options and previews. Now to start up with your first table use the following given format in your WP post:
[table] Domain,Company,Rank
Google.com,Google,1,
Facebook.com,Facebook Inc,2
[/table]
This is an example. You can create as many formats you want and each format should be enclosed in [table] and [/table] shortcode. Given format creates three columns: Domain, Company and Rank with three rows:
Domain |
Company |
Rank |
Google.com |
|
1 |
Facebook.com |
Facebook Inc. |
1 |
How To Add Automatically Resized Images In Your Blog Posts
If you post large number of images in your blog and resize each image to similar frame after you upload it. Then you may add an automatic task that will resize you images automatically:
- Copy the script from here.
- Create a new folder ‘script’ in your site root from cPanel.
- Upload this script in script folder and name it timthumb.php
- Use the following syntax for adding automatically resized image in your blog post:
<img src=”/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1″ alt=”” />
WP Hack For Customizing Logo Of WordPress Login Page
Add the following code block in your themes’s function.php file and replace the image name and address (in bold text) with your own image.
function my_custom_login_logo() {
echo ‘<style type=”text/css”>
h1 a { background- image:url(‘.get_bloginfo(‘template_directory’).’/images/custom-login-logo.gif) !important; }
</style>’;
}
add_action(‘login_head’, ‘my_custom_login_logo’);
WordPres Spam Words And Moderation
Here are words widely used in spam comments. Adding them to your moderation list protects your site from spam trackback and comments. Just copy-paste this list in your wp-admin/options-discussions.php (if using WordPress)
What is Moderation ? WordPress Comment moderation allows you to prevent comments to appear on your webiste before your approval. It can be useful for addressing Spam Comment.
How Moderation Works ? A new comment goes through many WordPress tests before appearing below your post. If comment fails one of the test conducted by WordPress then it goes to spam list, where you can approve or trash that particular comment. That’s how comment moderation works.
Akismet is a better option available for WordPress users for blocking Spam Comments.
Following is spam word list (released by WordPress) to add in your WordPress wp-admin/options-discussions.php
-online
4u
adipex
advicer
baccarrat
blackjack
bllogspot
booker
byob
car-rental-e-site
car-rentals-e-site
carisoprodol
casino
casinos
chatroom
cialis
coolcoolhu
coolhu
credit-card-debt
credit-report-4u
cwas
cyclen
cyclobenzaprine
dating-e-site
day-trading
debt-consolidation
debt-consolidation-consultant
discreetordering
duty-free
dutyfree
equityloans
fioricet
flowers-leading-site
freenet-shopping
freenet
gambling-
hair-loss
health-insurancedeals-4u
homeequityloans
homefinance
holdem
holdempoker
holdemsoftware
holdemtexasturbowilson
hotel-dealse-site
hotele-site
hotelse-site
incest
insurance-quotesdeals-4u
insurancedeals-4u
jrcreations
levitra
macinstruct
mortgage-4-u
mortgagequotes
online-gambling
onlinegambling-4u
ottawavalleyag
ownsthis
palm-texas-holdem-game
paxil
penis
pharmacy
phentermine
poker-chip
poze
pussy
rental-car-e-site
ringtones
roulette
shemale
shoes
slot-machine
texas-holdem
thorcarlson
top-site
top-e-site
tramadol
trim-spa
ultram
valeofglamorganconservatives
viagra
vioxx
xanax
zolus