How to change the name of the “Posts” menu item in WordPress

I’m currently working on a WordPress powered website, and needed to change the name of the “Posts” post type to something more suitable for that particular website. I browsed around the web and found this code snippet on new2wp.com.

function change_post_menu_label() {
	global $menu;
	global $submenu;
	$menu[5][0] = 'News';
	$submenu['edit.php'][5][0] = 'News';
	$submenu['edit.php'][10][0] = 'Add News';
	$submenu['edit.php'][16][0] = 'News Tags';
	echo '';
}
function change_post_object_label() {
	global $wp_post_types;
	$labels = &$wp_post_types['post']->labels;
	$labels->name = 'News';
	$labels->singular_name = 'News';
	$labels->add_new = 'Add News';
	$labels->add_new_item = 'Add News';
	$labels->edit_item = 'Edit News';
	$labels->new_item = 'News';
	$labels->view_item = 'View News';
	$labels->search_items = 'Search News';
	$labels->not_found = 'No News found';
	$labels->not_found_in_trash = 'No News found in Trash';
}
add_action( 'init', 'change_post_object_label' );
add_action( 'admin_menu', 'change_post_menu_label' );

In this particular example, “Posts” are changed to “News”. Just put this code in your child themes functions.php file. Of course, don’t forget to put it in between php tags.

<?php (code here) ?>

Very useful if you your website is not intended to be an ordinary blog. According to new2wp, this code was originally created by Mike Schinkel. Thanks Mike!

http://new2wp.com/snippet/change-wordpress-posts-post-type-news/

Quick start to the Google Web Fonts API

Google Web Fonts

I recently started playing around with Google Web Fonts, and I must say it truly is a slick solution of empowering web developers with quick access to a highly extended library of open source fonts.

The days of being limited by Arial, Times New Roman, Georgia, Verdana and just a few more standard typefaces may have finally come to an end. @font-face is an alternative way of implementing custom typography in web design, but this is somewhat more difficult and cumbersome to carry out. However, if you need premium typefaces @font-face, together with the paid service Typekit may be good solutions.

Implementing Google Web Fonts into your project is a piece of cake. Just browse around the Google Web Fonts page to find a typeface you like. Add the following code to your html file and replace “Tangerine” with whatever typeface you would like to use. If the typeface name consists of multiple words, just use a plus sign in between them: Kaushan+Script.

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine">

To start using the a font in your css code, just define it as you normally would. Remember not to forget fallback typefaces.

body {
  font-family: 'Tangerine', serif;
  font-size: 48px;
  text-shadow: 4px 4px 4px #aaa;
}

That’s it! To get get more detailed information on using the Google Web Fonts API check out the links below.

https://developers.google.com/webfonts/docs/getting_started
https://developers.google.com/webfonts/docs/webfont_loader

Moving your iTunes media library without losing its metadata

iTunes about window

It’s always painfully annoying when your hard drive dies on you (especially if you haven’t made any backup). This just happened to poor me. :’( Fortunately enough, I have got into the habit of making weekly backups of everything I have. In other words, I didn’t lose any data at all. This should be a lesson to all of you who doesn’t back up your important files!

Anyway, I therefore needed to move my iTunes library to a new drive. It turned out that there is no easy way of doing so, especially if you haven’t selected the option in iTunes to “keep iTunes media folder organized”. I didn’t want to lose all the metadata (ratings, plays etc.), so I tried to find an alternative way. I eventually found a method after digging around in forums (pretty hard to find) which worked out alright in the end, involving modifying all the paths in the iTunes XML database file.

  1. First of all, just in case something goes wrong, backup your iTunes library data (make sure iTunes is closed before doing so). These files can be found in <user-folder>\My Music\iTunes+ for Windows, or in /Users/<username>/Music/iTunes for Mac.iTunes library files
  2. Move your media library to the new location if you haven’t already done so.
  3. Start iTunes and select “File -> Library -> Export Library” in order to export your library XML database file. Save it wherever you want, e.g. on your Desktop. Close iTunes when you’re done.Export your XML library
  4. Open Library.xml in a text editor in which you have a “find and replace” function. Notepad in Windows is not good enough for this purpose, I would instead recommend Notepad++. On Mac OS X, TextEdit would work fine for this purpose, but only if it is set to plain text mode (not RTF mode). The point is that you need a plain text editor.
  5. If the only thing that changed when you moved your files is the drive name (Mac) or the drive letter (Windows), then do a find and replace and change the old drive name to the new name. For example, “wdDrive” -> “LacieDrive”.
  6. This will take a few minutes depending on the size of your media library. Make sure to save when finished.
  7. Now, open up iTunes and delete all the files, which you moved to another location, from iTunes. You can do this by selecting them and then right-clicking on them and choosing delete. If prompted, make sure to select the option for keeping them.
  8. After deletion, import the previously modified Library.xml by selecting “File -> Library -> Import Playlist”. Depending on the size this can take a long time. In my case it took about 15 min.Import Library.xml back into iTunes
  9. Done. Check so that everything turned out fine by playing some of the songs.

It seems like Apple should provide an easier way to do such an essential task as updating your file paths after moving your media library. Hard drives die all the time, right!

Remap a broken key

Remapping of space keyI recently had to fix a broken space key on the keyboard of a netbook. My first thought was to remove and check the broken key to check if it could be fixed. I found a temporary solution by increasing the pressure on it, but it just helped for a short time. Then I realized that it was of course possible to simply remap the key to another key which would probably never be used.
The system was fortunately Ubuntu, so with the power of the terminal at my hands it was not very difficult.
To remap it temporarily, you first need to run the following command.

xev

Remember or write down the key code being showed when pressing the key you want to remap to. In my case I wanted to use the key just next to the space key – keycode 102.
After finding the information with xev, you have to use the command xmodmap.

xmodmap -e 'keycode 102=space'

That’s it! Now you have two space keys; the broken one and the new one.

If you restart at this point the changes you made will be lost. You therefore need to make a shell script and make it run at start-up.

#!/etc/bash

xmodmap -e 'keycode 102=space'

Save this to whatever folder and file name you prefer (for example ~/scripts/remap_space.sh). You thereafter have to make it executable.

chmod u+x remap_space.sh

There’s many places where you can put your start-up scripts, it all depends on your distribution. One place that usually works is /etc/rc.local. Edit the file by using the following command (this depends on your distro and which applications you have installed).

rc.local script

sudo vim /etc/rc.local

or if you prefer the simpler text editor nano

sudo nano /etc/rc.local

Add the following to the end of rc.local.

exec /PATH TO YOUR SCRIPT/script.sh

for example

exec ~/scripts/remap_space.sh

Now you can restart your computer without the remapping disappearing.

That's awesome!

my desktop

Awesome could best be described by one word ‒ Awesome. I was never very fond of this slightly adolescent word used heavily by characters similar to Kelly from The Office. Nevertheless, I have come to change my mind lately, due to my entry into a new and exciting world consisting of tiling window managers. They always seemed a bit too hackerish, strange, and difficult to use for my taste in the past, but having used the tiling window manager named Awesome for just 4 days has made me completely change my mind on this point.

It truly is awesome! Blazingly fast, even compared to my previous choice of a quite ascetic and light weight window manager; Openbox, and way more efficient and fun than anything else I’ve used in the past. There is, however, a steep learning curve and you are required to spend some time learning and studying all the necessary keyboard shortcuts and also how to create a pop-up menu, your own shortcuts, auto-start of programs etc., by using the programming language Lua.

Tiling window managers work in a quite different way from standard floating window managers. It’s purpose is to enable you to work quicker by using the keyboard almost exclusively the keyboard.  In normal tiling mode, you cannot move around your open windows, they are always side by sides (tiling). You can change the size, change the layout and position of them with keyboard commands. In Awesome there’s a mode for making the windows floating for situations when you want to use for example GIMP which needs to have several windows floating around. Since there is no window decorations by default, you need to use a key command in order to initiate movement of the window, but it’s quite easy, just press one keyboard button (Win key) and then the mouse button. The strength of it is that you don’t have to think about where to place your windows, it handles this automatically for you.

awesome window manager

It should be said that it is a requirement to be quite familiar, and even to have a preference of using the command line, so if you have only touched the desktop part of Ubuntu or coming directly from OS X or Windows, I would advice not to dive into this environment head first. That experience could turn out to be damaging for your view of Linux in general. If you on the other hand is a person with experience in the usage of Linux and even the command line from now and then, I can highly recommend to give it a try. It’s not for everyone, but if it fits your needs it can be a very interesting, inspirational and changing experience.

http://awesome.naquadah.org
http://openbox.org