Back and Next

WordPress has some built in ways to call for commonly used bits of data like the title of a post or the date. Links to the “next post” and “previous post” are among them. You’ve undoubtedly seen them in their default form at the bottom of pages with >> or << next to them.

I thought it would be easy. Normally you just add a class to a link, then use css code to say what that class of link will look like wherever it appears.

I found out the hard way it’s not simple to add a class to the get_next_post_link or the get_previous_post_link function. And when I ventured out on the web to find a solution, it was harder than usual to find people who had already asked the question. Eventually, I found this helpful page by Justin Klemm.

It was scary because I haven’t touched the functions file before, but I bravely followed the instructions. (“I opened the functions file” is a bit like saying “I cracked open the patient’s skull and poked around inside…” because if you manage to really break a basic function, you may not be able to get back into the function file to fix it.)

Cutting and pasting Justin’s instructions did indeed work and I was happy with the result. Except for stubborn >> and << which insisted on showing up outside the button. Obviously the original WordPress function called for it and it didn’t put it inside my pretty buttons.

I immediately tried adding a label to the link but that caused the code to fail entirely. So I spent an hour poking around for more info. In the end? I added a label again. And this time it worked. I guess the first time, I missed a quote mark or a comma. And that, ladies and gentlemen, is how a simple problem can take hours to solve if a coder misses a single detail.

I am now going to try to limit the links to posts of the same kind, so texture tile series aren’t jumbled together with the blog posts. That should be easy as pie since WordPress expected a person might want to do that and has a filter already built in for it. I just have to call on it correctly. I feel just like Alice sitting down to lunch with the Red Queen.

“‘You look a little shy: let me introduce you to that leg of mutton,’ said the Red Queen. ‘Alice—Mutton: Mutton—Alice.’ The leg of mutton got up in the dish and made a little bow to Alice; and Alice returned the bow, not knowing whether to be frightened or amused.” – Alice Through The Looking Glass

June 7, 2016

Eos - illustration - flying origama lady

'Flight of the Origami Cranes' image licensed from 123RF.com

The background textures used on this page are from Eos Development's Cockle Flower Texture Tile Series