Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » WordPress

Dealing with Blank Lines in WordPress functions.php

Submitted by on October 17, 2012 – 1:06 am 5 Comments

This is an annoying little problem plaguing many WordPress themes: blank lines in the themes’ functions.php cause various random issues. The most common manifestation of this condition is the failure to save the “image” custom field. Below are a few commands to apply a quick fix. Unfortunately, these steps would need to be repeated every time you upgrade your theme, until the developers catch on. To simplify this task, I arranged the commands into a little script that will create a backup of your original functions.php and make the necessary changes.

The manual process is as follows: create a backups directory in your theme’s folder; backup the original functions.php; verify the backup; check functions.php for presence of blank lines; create a new functions.php without blank lines; copy the new file over the old one.

user@server.com [~/themes/arthemia-premium]# mkdir backups
user@server.com [~/themes/arthemia-premium]# cp -p functions.php ./backups/functions.php_`date +'%Y-%m-%d_%H%M%S'`
user@server.com [~/themes/arthemia-premium]# ls ./backups
./  ../  functions.php_2012-10-16_203706

user@server.com [~/themes/arthemia-premium]# grep -v . functions.php | wc -l
36

user@server.com [~/themes/arthemia-premium]# cp -p functions.php functions.php_new
user@server.com [~/themes/arthemia-premium]# grep . functions.php > functions.php_new
user@server.com [~/themes/arthemia-premium]# mv functions.php_new functions.php

A scripted solution would look something like this:
#!/bin/bash

# Change the path below to reflect the actual location of your active WP theme
theme_folder="/data/htdocs/krazyworks.com/wp-content/themes/arthemia-premium"
if [ ! -d "${theme_folder}" ] ; then echo "Folder ${theme_folder} not found. Exiting... ; exit 1 ; fi
mkdir "${theme_folder}/backups"
/bin/cp -pf functions.php "${theme_folder}/backups/functions.php_`date +'%Y-%m-%d_%H%M%S'`"
ls -als "${theme_folder}/backups"
/bin/cp -pf "${theme_folder}/functions.php" "${theme_folder}/functions.php_new"
grep . "${theme_folder}/functions.php" > "${theme_folder}/functions.php_new"
/bin/mv -f "${theme_folder}/functions.php_new" "${theme_folder}/functions.php"
echo "All done"

 

Print Friendly, PDF & Email

5 Comments »

  • Blake says:

    Most of the premium themes out there cost more than $50. I only have a small budget. If anyone can show me where to get cheap premium WordPress theme, it would be appreciated.

  • Duke says:

    I have found sites provide reviews of WordPress themes but very few of them offer SEO review of WordPress themes. Any of you know a site which offers tons of WordPress theme review in the SEO aspect?

  • PoohBearPenguin says:

    I’m designing my own WordPress theme from scratch and I can’t seem to figure out how to edit the next and previous page links to allow users to go to my older blog post. Anyone can provide a step-by-step tutorial for me? Thanks! :)

  • simply complicated says:

    I want to keep my regular subpages on my site (example: mysite.php portfolio.php,) but I want to use wordpress as well for the theme and use my own subpages instead of the wordpress pages. How do I use my wordpress theme on my regular subpages?

  • Shay H says:

    I found a WordPress theme that I absolutely love, and I wanted to use it on my LiveJournal. Is there a way to do this? I having a passing acquaintance with the custom designer settings on LJ, but I’m not sure if there is a way to ‘convert’ the theme I want to make it work.

Leave a Reply

%d bloggers like this: