Place code within the WordPress functions.php file…what?
Yes! You have been instructed by some WordPress technical writers on how to add some code to your functions.php file.[for the geekiness within us all] Only! It isn’t working! Darn! You have cut and pasted the snippet of code as instructed! But, all you get for your effort is ‘…Your PHP code changes were rolled back…..etc., etc!’ Or something like ‘…syntax error, unexpected ‘<‘, expecting end of file.’
I don’t know about you but…I was miffed! I am not going to gripe too much though because I am exhausted[lol!] from looking for a solution to this problem which, really, shouldn’t have occurred in the first place! Hmm…lack of…
One could say, in defence of writers publishing these ‘incomplete’ articles, that it is assumed, in this instance, that the reader has a working knowledge of PHP or even to some lesser degree of familiarity. If that were the case though, the immediate question arises: Why would such a person be reading a writer’s article on how to place code within the functions.php file in the first place? Yeah, don’t make sense, does it! Hmm…lack of perspective! I think these writers sometimes forget just exactly ‘to whom’ they are writing to…
In any event, and for this functions.php issue, I came upon some information that ensures your functions.php file operates properly after adding a snippet or more of code. Once saved, you will again see the familiar ‘File edited successfully.’ Just like mine…after I followed the article’s recommendations!
And since I don’t like to duplicate someone else’s work, I generally post the owner’s link instead. I know…not much for SEO but, the reader gets extra value! The link is RoseHosting: How to (Safely) Add Code to functions.php in WordPress and the piece was written by a fellow named Jeff Wilson. I have no idea who this person is (nor RoseHosting) except he has provided the working answer to what earlier…miffed me! Note: the article image, before the ‘Best Practices’ title, is a bit wonky but overall an informative piece of work!
Finally, I can definitively say “…and now I know the rest of the functions.php file story!’[a play on Paul Harvey’s famous quote]
Note : I say ‘incomplete’ meaning that the writer’s continuity of perspective has been broken! This is further ’embossed’ when one’s branded audience includes ‘beginners.’
Note : Link was checked (October 18, 2021) by Google’s Safe Browsing site status tool.