Categories

Because all themes are different, no single method will serve all themes perfectly. Please use this as an overview and not as an exact method.

For this demo, you will adding three tabs to all product pages. In the first tab, you will load up the product description. In a second tab, you will load up a snippet. In the third tab, you will load a static page.

In your WordPress theme folder, there lays the most powerful theme file known as functions.php. As the name suggests, this file adds unique functions to your WordPress installation. This file works just like a plugin within your theme. So you can modify/override WordPress core features without editing any core file. If used correctly, this file can do wonders for your WordPress site. It also speeds up development because you can have all the codes at one place. In this article, we will share some of the most incredible and most wanted tricks for the WordPress functions.php file.

Note: This article is targeted for WordPress theme developers. You may need have some PHP knowledge for some hacks.

Duh Moments: All codes in this article will be added to the functions.php theme file.

1. Add Google Analytics

Simply paste the code below and insert your Google Analytics where it says paste your Google Analytics. You can paste the code once in your functions.php file and never have to worry about it again. We are adding an action to the wp_footer, so it will automatically insert adsense codes wherever on all pages you have the wp_footer string.

2. Add a Favicon to your Blog

Every blog deserves to have its own identity. You can add this identity by adding the favicon code in your header.php file, or you can make it easier for yourself by simply adding the following code in your functions.php file.

Now whenever you are developing the theme, just upload the .ico file in the root folder where the blog is uploaded. You can also modify the file destination if you like. Often theme developers forget to change the URL of the favicon. This can eliminate another worry.

3. Remove WordPress Version Number

You should always encourage your clients to upgrade to the latest version, so you don’t have this problem. But if you are working with a client that does not want to upgrade, then it is essential that you remove your WordPress version number from your WordPress header, RSS feeds, and all other locations. To do this, add the following code:

7. Change the Default Gravatar in WordPress

Have you seen the default Mystery man avatar on blogs? Why waste the branding opportunity for your clients? You can replace the mystery man with a custom branded gravatar for your clients to give their site a unique touch. All you have to do is paste the following codes:

Don’t forget to upload a custom image to your theme’s image folder. Also change the name of the gravatar to their brand name. Once you upload the image and the functions, then visit: WP-Admin » Settings » Discussion

9. Rewrite Guest Author’s Name with Custom Fields

Now many blogs are publishing other authors also known as guest authors. A lot of these guest authors are one time writers. In this scenario, it is not feasible to create user accounts for them. This trick will let you replace the author name to guest author with the use of a custom field. Simply paste the code below:

01

add_filter( 'the_author', 'guest_author_name');

02

add_filter( 'get_the_author_display_name', 'guest_author_name');

03

04

functionguest_author_name( $name) {

05

global$post;

06

07

$author= get_post_meta( $post->ID, 'guest-author', true );

08

09

if( $author)

10

$name= $author;

11

12

return$name;

13

}

Now every time there is a guest post, simply add the custom field guest-author.

11. Custom Navigation Menus in WordPress 3.0

WordPress 3.0 comes with an awesome menu management system which theme developers can utilize to their advantage. If you want to give your users the option to use this core feature, then add the following function:

1

add_theme_support( 'menus');

Then you can call this function anywhere you like in your template file by pasting the code below:

12. Remove Default Author Profile Fields in WordPress

If you are creating a site where your client will be adding user information, then make the interface easier for them. One of the ways you can do this is by removing the unwanted fields such as AIM, Yahoo IM, Jabber etc. Simply paste the following code to remove these fields:

13. Add Author Profile Fields

If you want to create a more versatile author page, then you would need to add additional fields to the author profile. The code below will show you how to add additional twitter and facebook fields, but you can use it to add any other field that you like.

1

functionmy_new_contactmethods( $contactmethods) {

2

// Add Twitter

3

$contactmethods['twitter'] = 'Twitter';

4

//add Facebook

5

$contactmethods['facebook'] = 'Facebook';

6

7

return$contactmethods;

8

}

9

add_filter('user_contactmethods','my_new_contactmethods',10,1);

The function above will add something like this:

You can then call the fields in your author.php template by adding the following code:

15. Manipulate Your RSS Footer

Have you seen blogs that adds their advertisement in their RSS Feeds below each post. You can accomplish that easily with a simple function. Paste the following codes below:

1

functionwpbeginner_postrss($content) {

2

if(is_feed()){

3

$content= 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';

4

}

5

return$content;

6

}

7

add_filter('the_excerpt_rss', 'wpbeginner_postrss');

8

add_filter('the_content', 'wpbeginner_postrss');

We are calling a function wpbeginner_postrss to add in each post a content before the post saying This Post was written by Syed Balkhi and after the content Check out WPBeginner. But we add the function if(is_feed), so it will only be displayed in RSS Feeds.

17. Enable Threaded Comments in WordPress

Threaded comments is one of the best feature WordPress has. You can enable the threaded comments by visiting your wp-admin settings > discussion area, but you still need to add the JavaScript to your header file to make commenting easier. When developing themes, you want it to be as clean as possible, so stop cluttering your header.php file. Simply add the following function:

18. Remove Error Message on the Login Page

When you enter a wrong password or an invalid username, you get an error message in the login page. So if a hacker gets one thing right, the error message will help them identify that. You can stop helping the hacker by adding the following function:

1

add_filter('login_errors',create_function('$a', "return null;"));

Now when there is an error, you will see an empty box:

Not recommended for sites with multiple authors.

19. Disable Search in WordPress

When using WordPress as a CMS, sometimes the search feature becomes unnecessary. You can remove the search bar from the design, but the functionality still remains. You can add the following function and disable the search function:

20. Enable Adsense Shortcode

Adsense is one of the most popular ad elements used by bloggers. Theme designers can place the adsense box in one spot which limits the users. If you want to give your client the ability to add the adsense anywhere, then you can create a shortcode for the adsense using this function:

21. Change Your WordPress Feed Links without .htaccess

If you setup feedburner for your blog, then you should redirect your WordPress feeds to the feedburner feed links. This way you will not lose any subscriber. Normally users do it with a plugin, but you can do it for your client with this function:

22. Enable a Paypal Donate Shortcode

There are times when you are writing a post, and you get an opportunity to plugin your donate link. This function makes it easy for you by enabling a shortcode which you can use in your posts at any given time. Paste the code below:

23. Control When Your Posts are Available via RSS

All bloggers make errors that we catch after we publish the post. Sometimes even within the next minute or two. That is why it is best that we delay our posts to be published on the RSS by 5-10 minutes. You can do that by adding this function:

25. Custom Excerpt Length

By default the excerpt length is capped at 55 words. Many theme designers like to have the flexibility that is why WordPress lets you customize the excerpt length with this function:

1

functionnew_excerpt_length($length) {

2

return100;

3

}

4

add_filter('excerpt_length', 'new_excerpt_length');

Change 100 to the length you like.

26. Display the Most Accurate Comment Count

By default, WordPress counts trackbacks, and pings as comments. This inflates the comment count which looks really bad especially when you are not displaying the trackbacks and pings. To fix the count add the following function:

28. Display Twitter Followers Count and More

There are widgets that display Twitter followers count, but those are limited and ugly. You can use this function to customize the way your twitter followers count look on your blog. Simply paste the code below:

This list does not do justice to the power of the functions.php file. Entire theme frameworks are built solely on this one file. You can use it to add custom post types, create theme admin panels, and much more.

Additional Resources

Digging into WordPress – One of the best e-books for WordPress developers. It has some of the best uses of functions.php file.

Go to Any Design / Development related blog and type functions.php in their search to see what you can do with this file. Just on our site, you should be able to find 30+ articles about the uses of functions.php file. Try it for yourself: http://www.wpbeginner.com/?s=functions.php

Thanks to everyone who contributed in making this post possible on our Facebook Fan Page Everyone should join now, so you can help us write the post that you want.

WordPress is a powerful CMS. Sometimes a slight tweak can make your website inaccessible. However, finding a solution for any WordPress problem is extremely easy (check out how to properly ask for WordPress support and get it). In the past we have covered some of the most common problems WordPress users face. Like the internal server error or error establishing database connection. Another common problem that most WordPress users face at some point is WordPress posts returning a 404 Error. In this article we will show you how to fix WordPress posts returning 404 error.

Usually in this scenario a user can access their WordPress admin area, their blog’s main page, but when accessing a single posts they get a 404 Not found error. First of all, don’t panic most of the time your posts are still there and completely safe. This usually happens if your .htaccess file got deleted or something went wrong with the rewrite rules. What you need to do is fix your permalinks settings.

Go to Settings » Permalinks, and simply click on Save Changes button.

This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes the WordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.

Login to your server using FTP, and modify the .htaccess file which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .htaccess file:

01

# BEGIN WordPress

02

<IfModule mod_rewrite.c>

03

RewriteEngine On

04

RewriteBase /

05

RewriteRule ^index\.php$ - [L]

06

RewriteCond %{REQUEST_FILENAME} !-f

07

RewriteCond %{REQUEST_FILENAME} !-d

08

RewriteRule . /index.php [L]

09

</IfModule>

10

# ENDWordPress

Fix for Local Servers

Often designers and developers install WordPress on their computers using a local server for testing purposes. If you want to use pretty permalinks, then you need to enable the rewrite_module in the Apache configuration of your MAMP, WAMP, or XXAMP.

We hope this article helped you resolve posts returning 404 error in WordPress. Did this solution work for you? Do you have another solution that worked for you? Please share it in the comments below. We would like to make this article a comprehensive resource for users who run into this issue.

With the dynamic nature of WordPress, creating, using, and maintaining strong passwords is critical. Passwords help keep the good guys in and the bad guys out, enabling you to run a safe, secure WordPress-powered website. In this DiW tutorial, we’re going to show you how to change your WordPress password in virtually any scenario: logged in, locked out, and everything in between.

Change password when logged in

The first and easiest way to change your password is to simply login to your WordPress Admin and update your User Profile page.

The easiest way to change the WordPress password

This works great, and is the intended way of changing your WordPress password if you are able to login to your account. But what if you aren’t able to login to change your password? If you forget your password, it is impossible to change it using the WordPress Admin. So..

Change password when locked out

The second way of changing your WordPress password takes this scenario into account. If you forget your WordPress password and are unable to login to change it, simply navigate to the “Forgot Password?” page and request a new one:

..where “domain.tld” is the location of your WordPress installation. Once you request a new password, an email is sent to the email account with which you registered. In that email is a link to reset your password, which is finally sent back to your email account. The process takes a while, but seems to work fine assuming you have access to your registered email account. Without access to that email account, it is impossible to change your WordPress password using this method. So..

Change password like a ninja

The third way of changing your WordPress password bypasses the need for an email account by modifying the database directly. All that’s needed is a way of interfacing with your database. Here, we’ll be using the incredibly awesome phpMyAdmin.

To change the password directly via the database, simply login and locate the username of your account in the “users” table (click on the “Browse” tab to see a list of users). Click to edit the entry for your username, and then scroll to the “user_pass” field:

The WordPress users table with highlighted “user_pass” field

After clicking the “Edit” button, you will see something similar to the following:

The Edit screen for your Username’s user data

Notice the long string of random-looking text? That’s the MD5-encrypted version of your current password. You know, the one you forgot. To change it, you’re gonna need to encrypt your new password. To do this, you have several choices:

Encrypt a new password using a web service

The first way to generate a new MD5-encrypted password is to use a free web service such as this one. Simply enter your plain-text password (i.e., the complex phrase you want as your login password) and then click on the “Encrypt” button (make sure to select “MD5” as the encryption type). Once the service spits out the encrypted version of your password, copy and paste it into the user_pass field described above. Save your changes and you’re good to go.

A free online password-encryption service

Encrypt a new password automatically using phpMyAdmin

Of course, there is a much easier way of changing your password via the database. If you are using phpMyAdmin, simply enter the plain-text version of your new password in the user_pass field. Then, in the left-hand dropdown menu, select the MD5 option and click “Go”. This instructs phpMyAdmin to encrypt your new password with some fresh MD5 hash. Mmmm, that’s all there is to it.

The MD5 encryption option next to the User_pass field

Encrypt a new password via SQL query

The easiest way to reset your password with a MD5-encrypted hash is to simply execute the following query via the SQL command console:

Before executing this query, change the “newpassword” string to your new password and edit the user-login name (“admin”) and table-prefix value (“wp_”) if necessary.

The SQL command console, locked and loaded

Viola! It’s that easy. Keep in mind that MD5 is designed for one-way encryption — you can use this method to encrypt new passwords, but you will not be able to decrypt existing passwords. It’s strictly a one-way street, so be sure to keep your passwords someplace safe to avoid having to do this again.

was recently working on a client’s site and they needed a countdown timer to display in the header. They settled on a plugin, but the plugin looked horrible in Internet Explorer (IE). The labels for weeks, days, hours, minutes and seconds were popping way out of their boxes in IE9, and not showing at all in IE8.

I couldn’t figure out what the issues was with the CSS…possibly a conflict with the Genesis Child Theme we were using, but I needed to find a solution.

Internet Explorer – the bane of most web developers’ existence. Up to 60% of your development can be wasted just trying to squash out IE specific bugs which isn’t really a productive use of your time. In this tutorial, you are going to learn about the most common IE bugs and rendering disparities and how to easily squash them or deal with them. Interested? Let’s get started.

DataTables is open source software, free available for you to use and modify. The DataTables distribution include a wide range of examples, the source files (including compressed versions) and all first class plug-ins. Download using the button below