Wooden Fence and Leaves by Barb Ballard (scidmail) on Stock.xchng

Separating Presswork Theme Customizations

One of the fundamental problems with tweaking a theme is that, when it is inevitably updated, the new files will undo your changes.  Typically, when I update a theme, I need to remember to (a) add back in my Google Analytics code, (b) add back in my meta tags for Google and Bing Webmaster tools, and (c) fix anything else that has been overwritten.

I liked the Arras theme for its separation of CSS.  When I selected Presswork, I started adding in my CSS changes to the global style sheet.  I also started tweaking the actions.php file to enable the theme to do a couple of small things that I wanted.  This is not optimal because it means I have to document my changes so that, in event of an update, I can re-insert them.

It was useful to read this post about NOT hacking the actions file and, instead, create a custom CSS and custom actions file that Presswork will incorporate.  The CSS was a no-brainer, so I dragged my style customizations over into a file called custom.css, placed it in the /wp-content/uploads folder, and Presswork immediately adopted the styles.  When I forced my site’s cache to empty and do a refresh in my browser, the site looked exactly the same despite the global style sheet lacking my original changes.  They had all been added from my custom file.

The custom-actions.php file was not as simple for me to get working.  This is largely because I’m usually operating just on the edge of my known universe.  It took me a while to parse what the examples meant.

You create the custom-actions.php file and drop it in the same /wp-content/uploads folder.  The file needs to start with a <?php and end with a ?>.  You can then add your own actions into this file.  What I wanted to do was to customize actions (functions) that they had in the original actions.php file.  I copied and pasted the pw_posts and pw_single_post functions (essentially everything between the function line that starts off the function and the next large comment line (look for the pound or hash # characters).

No problem.  Saved the file.  Gave it the correct permissions and ownership on the server and refreshed the site.  Bonk.  Something was wrong in the file, and my site would no longer respond.

The trained eye (developer) will not have made this error.  Since I was using the original functions, I needed to include a remove_action call before each of the function to disable the original function, pick up the new one, and then activate it.  [For all I know, I have this wrong, but it worked, so I’m going to stick with it for now].  At the bottom of each of the two functions were a number (5 and 2, respectively) of add_action() lines.  I copied and pasted those from the bottom of the function to the line above the function, changed them to remove_action(), and then edited the name of the function.  For example, I started with:

<?php

function pw_posts() {

and, after cutting and pasting and changing the necessary lines, I had

<?php
remove_action(‘pw_archive_post_middle’, ‘pw_posts’);
remove_action(‘pw_author_post_middle’, ‘pw_posts’);
remove_action(‘pw_category_post_middle’, ‘pw_posts’);
remove_action(‘pw_search_post_middle’, ‘pw_posts’);
remove_action(‘pw_index_post_middle’, ‘pw_posts’);

function custom_pw_posts() {

 Then I went back to the bottom of the function, and edited the original add_action line so that, instead of using pw_posts, it used my new custom function, custom_pw_posts.  I know, this probably seems obvious to anyone with half a wit who read the original Presswork blog post so perhaps I need some reading glasses or need to spend more time on the site.

I repeated it for the pw_single_post function, saved the file, reloaded my site, and I was in tall cotton.  To make sure that it had worked, I reinstalled the original Presswork files, and my tweaks were still working.

This is a great way to balance the benefit of a nicely designed, free WordPress theme with the inevitable interest that sites have in customizing the theme.  By separating out the cascading style sheet and actions.php files so that customizations are not lost between upgrades, it means that maintaining and personalizing a site that relies on Presswork becomes that much easier.  Yet another positive for using this great theme.

Leave a Reply

Your email address will not be published. Required fields are marked *