The Safest Way to edit WordPress Function File

This is a guest post by Dana . Register and start guest posting here on Serradinho. You can also increase your monthly income by joining our Revenue Sharing Program. You have nothing to lose and so much to gain!

As you may already aware that WordPress function.php is really important for our WordPress blog. Function.php consist of many PHP functions which makes our WordPress blog run properly and have other features. Therefore, if we mess up with our functions file, surely our WordPress blog will be a disaster.

edit function file risk The Safest Way to edit WordPress Function FileFrom my own experience, a tiny error in the functions file could result in your blog being down or not available. This only means that customizations to the functions file is really a high risk task. There are many bloggers who avoid editing the functions file due to this risk.

As a blogger which is really serious about attaining our goals and taking our blog into the next level – we eventually do edit the function.php file with our customizations and the results are noticable.

It is because after doing many WordPress customizations by utilizing the theme features, so we need do some PHP coding, we will find that the theme features are able to fulfill our requirements.

Do function.php customization for author bio creation

And that’s what I found out when trying to make the author bio show in each post right after blog post and before related post list. After doing some research on the internet, I finally found a way to accomplish it via a tutorial. A way that required some customization by adding some PHP code.

At that time, I was not aware how important the functions file really was. I just added the PHP code in the functions file, which was of course the wrong code. It made my blog appear broken, which only showed an error message when I tried to browse it.

George has previously written a guest post about creating the author bio box over at ThesisThemeHQ.com. Go have a look and try it out as there are also other customizations listed.

My Blog Function.php is broken and the learning curve

My blog was broken because of the coding customization that I added, no doubt about that. I could not even access my WordPress dashboard to undo the coding. The only way to solve this was with direct access to the functions file via my favorite ftp client, FileZilla.

After editing the functions file, it worked again and I surely learned a huge lesson. I learned that I really need to be careful when editing the functions file. If some code is wrong, it will make my blog go down – including the admin page (WordPress backend). After that bad experience, I’m rethinking about editing the functions file.

edit function file learn The Safest Way to edit WordPress Function FileI even thought of leaving the customizations to a professional web designer to do. But then, I’m aware that I will never learn anything if I go that route.

And I will surely need to learn about it if want to get my blog to a higher level and if I also want to became a great webmaster. So, I finally decided to continue doing customizations on my own, but also that I need to be more careful when doing so.

Therefore, I do my research once more through the internet. This time I researched how can I do customizations safer. And I found the way – the way that can minimize the customization risk.

But – it is really high risk. Should we do it? If we should, how can we minimize the risk?

wordpress img The Safest Way to edit WordPress Function FileOf course we should do customizations as mentioned before. We can minimize the risk, we can even make the risk become zero.

In this article, I will share how we can freely try to create new functions without messing with current functions file and it will make us have zero risk.

We can create a new customization functions file (as example: customized-function.php) as our place to add and customize new functions. We surely can feel free to try new functions on it without being afraid to mess up our current functions file.

We use a separate php file for it. Our current blog theme use function.php as function source, and we do our customizing in customized-function.php.

But, if it is separate, how can our current theme use the customized-function.php?

We can put a command in functions file to call customized-function.php each time. We put the following code in function.php file:

include_once (TEMPLATEPATH . ‘/customized-function.php’);

The above code will tell our blog theme to also load the customized-function.php each time the function.php is loaded by our blog theme.

Final Words

Now, we can freely create new functions or customize the old function file without being afraid to affect our blog. We can always isolate customized-function.php from the current theme if some errors happen by commenting the code out in the functions file. This tip is simple and easy to implement and could save us a lot of pain in the end.

What do you think? Do you do something similar? Do you add new functions or do you purchase a theme which already has all this done?

  • Twitter
  • Digg
  • Delicious
  • Submit post to StumbleUpon
  • Submit post to Facebook
  • Submit post to LinkedIn
From the desk of Dana

Dana is the founder of Blogging Tips Blog , a blog where he share much about blogging tips, and little about internet and IT. Yup, You will find knowledge sharing about blogging, Internet, and IT in his blog. You can subscribe the LetUpdate dot Com Feed or twitter @danalingga to be updated

View all posts by , there might be other posts that interest you.

{ 28 comments }

Sachin @ Web Design Mauritius May 26, 2010 at 8:22 am

Hi Dana,
thanks for the great article, I really appreciate the “I’m aware that I will never learn anything if I go that route” part because this is all it takes to find the inspiration needed to dive into the code and learn some things. It’s even better when you share the things you learn.
.-= Sachin @ Web Design Mauritius´s last blog ..Custom Search: make the most out of Google Maps with optimized geolocation results =-.

Dana May 26, 2010 at 1:50 pm

Thanks Sachin for liking my writing and for the part that you quoted.
.-= Dana´s last blog ..Theme Junkie Great Discount: 50% Off =-.

Kurt Avish May 26, 2010 at 8:26 am

Really nice tips George. I am one who often sabotaged my own blog while editing functions.php and I had to access via ftp to correct. The worst is when you forgot to backup a copy of the original file and has to look all over the functions again.

Nice tip. Bookmarked.
.-= Kurt Avish´s last blog ..The 3 First Things To Do After Installing Wordpress =-.

George Serradinho May 26, 2010 at 10:24 am

@Kurt – thanks, but this is a guest post by Dana. The credit should not go to me.

You always have to make backups before and after, to ensure you have everything.

Josiah | Free iPad May 27, 2010 at 1:01 am

Ahh, neat trick. I can admit to screwing up mt WP installs several times by editing key files. I usually end up restoring the files via my host’s backup service. This is a lot more convenient though.
.-= Josiah | Free iPad´s last blog ..Yankees Standium Bans the iPad =-.

Dana @ Blogging Tips Blog June 28, 2010 at 9:32 am

Yup, with this we isolate the problem source. :)

Dennis Edell | Direct Sales Marketing May 27, 2010 at 1:06 am

So you do everything in the new customized section, and if you screw it up, it doesn’t touch the blog itself…very cool. :)
.-= Dennis Edell | Direct Sales Marketing´s last blog ..I asked – You Answered – 4 more Social Icons Added =-.

Dana @ Blogging Tips Blog June 28, 2010 at 9:33 am

Yes, it is. With this, every the recovery will be faster if there is something wrong.

blinkky May 27, 2010 at 9:10 pm

For me, I’ll backup first before editing my blog script =)
.-= blinkky´s last blog ..Unique Optical Mouse Design =-.

Dana @ Blogging Tips Blog June 28, 2010 at 9:34 am

The backup is a must for both traditional way or this way.

Arafat Hossain Piyada June 1, 2010 at 5:13 am

Some day ago I too faced the same issue, in my case I started to edit it offline using Notepad and always take a backup before editing. Nice information for me to get protected in future.
.-= Arafat Hossain Piyada´s last blog ..PenyuLocker – A free folder locking software =-.

Dana @ Blogging Tips Blog June 28, 2010 at 9:35 am

Glad if it help you. :)

My Marketing Rules June 9, 2010 at 4:43 am

Great post and well written. I can relate to making mistakes in my wordpress php. I will try to take note. thanks again.

Dana @ Blogging Tips Blog June 28, 2010 at 9:35 am

You’re welcome mate. :)

Shiva | Web Magazine June 11, 2010 at 8:13 am

Dana, Awesome post. You are quite right. Editing the function.php file without backup or guidance can very very risky and may screw up your site. The way you mentioned i.e. by making a customized-function.php and calling it with the function.php is quite good. Thanks a lot for this awesome tip

Dana @ Blogging Tips Blog June 28, 2010 at 9:38 am

We should very careful in function.php customizing. And what I write here is one way to isolate the problem if present.

sliding shelves Chicago June 12, 2010 at 8:38 am

Very cool tutorial. I never realized that you could edit WP that way! It’s really really tempting to just hand this to a professional though. But you’re right, how else are we going to learn unless we try it out ourselves.

George Serradinho June 14, 2010 at 8:13 am

@Sliding Shelves – you are so correct. One needs to give it a try and see what the outcome is otherwise one will always be lazy and never learn.

Whiztechy June 12, 2010 at 9:03 am

Hey Dana, I keep on playing with my function files but I always try to be safe with files thus take a backup in advance. Thanks for sharing.

Dana @ Blogging Tips Blog June 28, 2010 at 9:39 am

It is a must to play safe when do function file customizing.

Udegbunam Chukwudi Make Money Online June 24, 2010 at 1:38 am

Lord knows I’ve ruined my blog on more than two occassions all cause I was careless when adding or removing stuff from my functions.php file. As at now I always backup my functions.php file before embarking on any changes whatsoever ;-)

Dana @ Blogging Tips Blog June 28, 2010 at 9:41 am

The backup is a must, however with this way, you still able to recover fast even though without the backup.

Sherwin June 26, 2010 at 1:28 am

I am trying out the solution on a TEST installation before i do it on my real blog but i am having some major problems.

First i created the customized-function.php file and uploaded inside my thesis_17 folder. Then i edited the custom-function.php file from inside the wordpress admin by adding this line ….

include_once (public_html/etrainingtt/wp-content/themes/thesis_17 . ‘/customized-function.php’);

I would assume this is my TEMPLATE PATH …. public_html/etrainingtt/wp-content/themes/thesis_17 but i always get php errors that makes my wordpress useless and i have to delete the installation and start over again.

This solution will help me a lot but what am i really doing wrong?

George Serradinho June 28, 2010 at 9:13 am

@Sherwin – I see you have the full path and then still the single quotes. Please use the following instead and see if it works:

include_once (“customized-function.php”);

N.B. Please double check that the double quotes are correct as the comment might change it a bit.

Sherwin June 28, 2010 at 7:18 pm

Thank You for your suggestion … It worked fine now. I just bookmarked your blog as well as Dana’s because i found some excellent articles that will help me along the way …. Thanks to both of you

Dana @ Blogging Tips Blog June 28, 2010 at 9:43 am

As George said, you do not need to put the whole path. However, if it is still can not work, there are may some function conflict with the theme. It may happen with complex theme such as thesis.

Tracy June 30, 2010 at 6:24 pm

Really as long as you make up backup and only do a change at a time you will not have problems when making changes to the function file. This way if what you do messes it up you can always go back to what you had that worked.

George Serradinho July 1, 2010 at 8:10 am

@Tracy – yes, I always make backups before I start to make changes.

Comments on this entry are closed.

Previous post:

Next post:



    

Join our Revenue Sharing Program today.

Follow George Serradinho on Twitter - username: @gfserradinho.   Connect via Facebook.   Connect via LinkedIn.   Follow George Serradinho on Google.   Connect via YouTube.   Connect via Skype.

*/ ?>