Upgrading WordPress – A Peack under the Hood

What happens when we click Upgrade Now?

  • WordPress creates automatically a file named .maintenance
  • All these files might be overriden:
    • All the files under /wp-includes/
    • All the files under /wp-admin/
    • Any wordpress’ original theme folder (Twentyten, Twentyeleven etc..) under wp_content/
    • All files directly under wordpress’ root
  • A couple of files/folders may be added to wp_content/
  • On the database, The “db_upgraded” flag on the wp_options table is set to “0”
  • If all went well, WordPress deletes automatically the .maintenance file

Once done, the right db and system versions are recorded on the wp_config.php file:
* The WordPress version string
* @global string $wp_version
$wp_version = '3.1.3';

* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
* @global int $wp_db_version
$wp_db_version = 17516;

If anything goes wrong – here’s an interesting article with some suggestions for troubleshooting.

Adding Scripts and Style only to a certain Page on WordPress

Sometimes we want to add a script or a css file only to a certain page. How can this be done?

Here’s what happened to me: I needed to insert a code snippet on a page. The snippet was generated by a third party. In fact – it was a form, and the form’s code, already ready, also contained the action for the form, on a galaxy far, far away. I.e. – remote server, not a part of the site.

That means – most of the work already done. All is needed is to paste the piece of code on a page, and let the 3rd party action page deal with the rest. Unfortunately, even when a remote server takes care of the form data, it is still our responsibility to validate it on the client side. So further to adding the html code for the form, we need some javascript to actually validate it. To do so, I wanted to call an external jquery plugin called validationengine. Question is: how do I call this script only on the form’s page?

So the first thing we do, is create a unique template for the form page. Having done that we go on to the next stage

What we need to do now, is creating 2 hooks that will be called and affect the content of the page’s head. The first hook, when called, will register the necessary js files, and the second hook will add a line to the head html: a call for the css file.

In this example I will demonstrate adding some script that take care of form validation, but you may use the same technique for anything you want.

So it is time to add some code to our functions.php file. You can find this file on your theme’s directory. If you don’t find it – don’t worry. Just go ahead and create one. Open the functions.php file with your favorite text editor and write down:
function print_form_scripts () {
wp_enqueue_script('validationEngine-en', get_bloginfo( 'template_url' ).'/jquery.validationEngine-en.js', array('jquery'));
wp_enqueue_script('validationEngine', get_bloginfo( 'template_url' ).'/jquery.validationEngine.js', array('jquery'));
function print_form_styles ($content) {
$content .= '<link rel="stylesheet" href="'.get_bloginfo( 'template_url' ).'/validationEngine.jquery.css" type="text/css"/>';
echo $content;

The first function (print_form_scripts) when called, will register a couple of scripts to the page,
The second function (print_form_styles) when called, will add an html line to the head content, a call for a css file, that is relevant for the form validation.

Now, all is left to do, is actual hooking of these functions to the wp_head action.

In order to do so, open your new page’s unique theme file (page-NNN.php) and add these lines, before the call for the get_header() function:
add_action('wp_print_scripts', 'print_form_scripts');
add_action('wp_head', 'print_form_styles');

Keep in mind, that these lines should be added to the file before the call for the theme’s header file (get_header()), as they are hooked to wp_head, which in its turn, is called from within the header file.

Having done that, you can refresh the page and check it’s html hitting “view source”, and see that indeed the calls to the requested js and css files are added to the head html, for this page only.

Customizing a Page on WordPress

It’s always recommended to be consistent with your site’s look and feel. However, there may be a time when a page calls for a unique look and feel. Be it you homepage, or a special landing page, or a complex form. For those cases there should be a way to customize a unique page without affecting other pages’ appearance, and indeed, there is. In fact, there are at least two.

WordPress has a theme hierarchy. Which means that whenever a page is loaded, the system detects its type, and calls for a ceratin template file from your theme directory. If that file is missing, WordPress will fall back to the next in line.

For page display, WordPress will look for a theme file called page.php, however it will look first for a file called page-NN.php, where NN be the pages id.

So if your special page’s ID is 44, create a file in your theme’s directory, called page-44.php, and use it to customize your page layout. Even better would be to save the page.php file as page-44.php. That way you already have a base that you can start work on.

You can also create a file named page-my-new-landing-page.php, where “my-new-landing-page” be your special page’s slug. Yes, before WordPress looks for a page-NN.php, it looks for a page-SLUG.php!

Read more about WordPress theme hierarchy here.

Using a theme file

Sometimes you need to customize not just one page, but a couple of pages. For example, a series of landing pages. In this case, you will be better off setting a special template file to rule them all.

First thing: Create a file in your theme directory, and give it a name. For instance: “landing_page.php”.

Open the file with your favorite text editor and add these lines:

* Template Name: Landing Page Them
* A custom page template for landing pages

The “Template Name” bit is the identifier of this theme.

Once this is done, go to the back office and create or edit a page. When the page is open for editing you will notice on the right hand side the “template” drop-down menu. From this menu you can now choose your new template for this page, and others.