Monday 28 October 2013

Detect And Redirect Android Users With PHP

Here is a simple trick to redirect Android users with some simple PHP script. It's a useful snippet if you have an Android version of your website.

Add following PHP to your document to search and redirect Android user agents:

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
    header('Location: http://android.yourwebsite.com');
    exit();
}

More tricks like this are on their way...

Allow Contributors To Upload Images In WordPress

Are you running a WordPress website with bunch of contributors who are willing to post on your website? If yes then this article contains a great tip for you.

As I mention on previous articles, every post on your blog must contain at least one image related to the article. It's really great for SEO and other things.

This code will help us to allow users with contributor role to upload images on your WordPress site.

Add this code to your functions.php file:

if ( current_user_can('contributor') && !current_user_can('upload_files') )
     add_action('admin_init', 'allow_contributor_uploads');
    
     function allow_contributor_uploads() {
          $contributor = get_role('contributor');
          $contributor->add_cap('upload_files');
     }

Thursday 24 October 2013

How To Disable Smart/Curly Quotes In WordPress

There are lot of word processor programs which itself converts all yours simple quotes to curly quotes (aka s mart quotes). It looks like small figures six and nine raised above the baseline (like 6...9 and 66...99).

It's a huge problem if you're writing codes in your posts as WordPress automatically converts all quote symbols to smart quotes. So if anyone is copying a snippet from your blog post would have problems with running to code in their own text file.

You can easily disable this feature with a small snippet. Just add following snippet to your functions.php file:

<?php
remove_filter('the_content', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
?>

That's it!

Wednesday 16 October 2013

Send Email Notifications When User Submit A Post In WordPress

Are you running a multi-author WordPress blog or a blog with guest posters with contributor role to submit the post directly from the WordPress dashboard? Then you must be looking for a way to get email notification when someone submit a post or when you publish or reject their post.

We previously shares some great scripts to get email notifications for a couple of events, but this time it's a plugin.

WP Status Notifier is all you're looking for!

The plugin sends an email to the admin (or selected user) when ever some one submit a post for review and when you publish or reject their post, author will get instant emails. After installing the plugin, you can access it’s setting under Settings > Post Status Change Notifications.

WP Status Notifier's interface is not much complicated, as you can check it below:


It's a great plugin, but if you want some advance options, then you can also use Post Status Notifier Lite.

Personal Note: First of all, Eid-Mubharakh to all my Muslim readers. I'm going out on a small seven day trip tomorrow, so don't expect me to post any articles here on BWidgets. Thanks for all your support!

Sunday 13 October 2013

Prevent Directory Browsing With .htaccess

I recently shared several articles about .htaccess file, and as you may know by now, it's a great file if you're working on the security of your site. Today we'll disable the directory browsing in our website with some editing in .htaccess file.

You know how you can change a few characters in a URL and continue browsing the website. Sometimes, it could be very dangerous for our website, so it's time to prevent directory browsing.

Add following snippet to your .htaccess file:

# directory browsing
Options All -Indexes

Save the file, and that's it!

How To Remove Footer Credits From Jetpack Mobile Theme In WordPress


Jetpack is a great plugin for WordPress to connect your blog to WordPress.com. It also gives us dozens of crappy great plugins for our blog, such as mobile module, social share, wp.me short links, and more.

Jetpack's Mobile module is great plugin to create a mobile version of your website for mobile users, but it comes with a footer credit: Proudly powered by WordPress.

Giving WordPress their credit for their hard work is not bad, but if you're interested then you can easily remove the Jetpack.

In your file manager, edit footer.php file which can be found inside public_html/wp-content/plugins/jetpack/modules/minileven/theme/pub/minileven

Just remove this code from line #27:

<a href="<?php echo esc_url( __( 'http://wordpress.org/', 'jetpack' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'minileven' , 'jetpack'); ?>" rel="generator"><?php printf( __( 'Proudly powered by %s', 'minileven' , 'jetpack'), 'WordPress' ); ?></a>

That's it.

Friday 11 October 2013

Protect Your wp-config.php File With .htaccess

As a webmaster, it's our duty to take care of our website. And security is our #1 priority when it comes to take care of a blog. As we know, there are millions of security issues with WordPress, which can be solved with some simple things, such as security plugins, configuring our .htaccess file, etc.

Today we'll secure our wp-config.php file with some basic .htaccess editing. Add following code to your .htaccess file:

<files wp-config.php>
order allow,deny
deny from all
</files>

This code should be placed in an .htaccess file located in the directory that contains your wp-config.php file.

Thursday 10 October 2013

Optimize And Repair WordPress Database

In WordPress 2.9, WordPress gave us a new automatic database repair feature. This feature enables you to repair and optimize your database. You should use this feature time to time to take care of your website's home.

You can use this feature even when you're not logged in to your website. This is because its main intent is to repair a corrupted database, Users can often not login to their WordPress when the database is corrupt.

Just add following snippet to your wp-config.php file to activate this feature:

define( 'WP_ALLOW_REPAIR', true );

Once activated, you can see the settings on this page: http://www.yoursite.com/wp-admin/maint/repair.php

Once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.

Send Email Notifications When User Role Changes In WordPress

Yesterday I shared a code which sends an email to the user when the user updates their profile. Today I have something similar, but a bit different. This code sends an email the user when the user's role has changed.

It's a great way to let a member know about the role changes that you'll make. It's also a great trick if you're running a WordPress site with bbPress forum or multiple wirters & contributors.

Just add following to your functions.php:

function user_role_update( $user_id, $new_role ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "Role changed: ".$site_url."";
        $message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
        wp_mail($to, $subject, $message);
}
add_action( 'set_user_role', 'user_role_update', 10, 2);

That's it.

Wednesday 9 October 2013

Increase Maximum Upload File Size Limit In WordPress

Sometimes, you need to upload a large file to your site. If you run a WordPress site with audio podcasts, videos, and .zip files, then you may need to increase WordPress' default 32mb limit.

There are lot of ways around the internet to increase your WordPress max upload file size, but most of them are not much hardy. But a little snippet by Word Impressed can solve your problem. You can easily increase or decrease your maximum upload file size limit.

Create a php.ini file (using notepad document) and upload it into your /wp-admin/ folder and add following snippet into the file:

memory_limit = 32M
upload_max_filesize = 32M
post_max_size = 32M
file_uploads = On

You can change 32m in the above code to whatever max file size you want.

Popular Posts

 
Powered by Blogger.