How to Make your Page Title Different From your Menu Title in Word Press

Word press by default takes the title of your page and uses it for the menu title too. This can be annoying if you want to have say “Welcome to my Website” as your title on your page but only reference it as “Home” on the menu bar.

So I hear you say ‘why not create a custom menu as you can label the menu items?’ Yes you could but from my experience if you are dealing with clients who don’t really know what they are doing you need to make it as simple as possible. The custom menu doesn’t automatically update the menu items when new pages are added by default. With my method the menu is still updated automatically.

This is actually really easy to solve with a little bit of PHP and using the custom fields section when making your page.

So first create your page and call it ‘Home‘  this will be used as the menu item name. Now make a custom field on your page called ‘pagetitle‘ and add the value you want for your main page title.

Now open your ‘page.php‘ file and add the following code;

First at the top add this line, which gets your custom field and assign it to the var ‘$meta_values

[sourcecode language=’php’]

ID, “pagetitle”, true); ?>

[/sourcecode]

Now find any reference to ‘the_title();‘ usualy found in <h2> and <h1> tags and replace with the following code;

[sourcecode language=’php’]

[/sourcecode]

What the above does is checks if you have actually made a custom field for that page, if true it will use that field as the main page title. If not true it will just use the same value you originally named your page. This way you don’t have to add a custom field to all your pages, only the ones you want to have different page titles too.

Simple!

Useful Crontab Commands

I always end up searching to double check how to run programs at specific times using the Cron tab, so here are my useful ones.

First here’s a key to how crontab works.

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of the month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Here are some commands to edit the crontab, note knowledge of using vi is pretty important here 🙂

Edit your crontab file, or create one if it doesn’t already exist.
[sourcecode language=”sh”]# crontab -e[/sourcecode]

Display your crontab file.
[sourcecode language=”sh”]# crontab -l[/sourcecode]

Remove your crontab file.
[sourcecode language=”sh”]# crontab -r[/sourcecode]

Here are some practical examples.

Daily at 4am.

[sourcecode language=”sh”]

0 4 * * *  path_to_program_to_run

[/sourcecode]

Weekly at 4am on Monday.

[sourcecode language=”sh”]

0 4 * * 1  path_to_program_to_run

[/sourcecode]

Monthly at 4am on the 1st of the month.

[sourcecode language=”sh”]

0 4 1 * *  path_to_program_to_run

[/sourcecode]

Monthly at 4am on the 1st and 15th of the month.

[sourcecode language=”sh”]

0 4 1,15 * *  path_to_program_to_run

[/sourcecode]

Using a Flash XML Object as a String

Thought I better blog this as I wasted a good hour trying to do what I thought was so simple.

Please note I am only showing part of the code.

I was trying to pass the value of the following pageURL var to any function or even a simple output of trace(pageURL) but it just spat out undefined 🙁

[sourcecode language=”php”]
xmlNode = this.firstChild;
var pageURL = xmlNode.childNodes[36].childNodes[i].firstChild;
trace(pageURL);
[/sourcecode]

I finally found out that you have to add toString() at the end for it to work. 🙂

[sourcecode language=”php”]
xmlNode = this.firstChild;
var pageURL = xmlNode.childNodes[36].childNodes[i].firstChild.toString();
trace(pageURL);
[/sourcecode]

Something I will always remember in the future when working with XML nodes.