Monthly Archives: January 2013

Learning About Cookies – Not the Delicious Kind, but it Still Made Me Feel Great!

Cookies for Geeks

Great idea for corporate gifts from a Russian tech agency! See story on Behance

You know those times when you do something people didn’t think you could do? Those times are pretty much week-makers for me.

Today, a client had a problem with language selection and persistent cookies (where return visitors to a site their language settings are saved from any previous visit).

Someone (not naming names) was asking everyone in the office for help…except me.

Infuriated, I piped up and said that as I am doing all this coding study – I would be happy to look into it. (I am pretty sure they expected me to come back empty-handed.)

The first thing I did was to have a look at all the cookies they currently had on their site. This is where I noticed the first big red flag – apart from cookies from other sites (Google, social sharing, etc), their cookies were all single session.

We needed to change their cookies to include an expiration date, so that their cookies would become persistent cookies.

The second thing we needed to do was to set a variable on each page to show what language that page is, and include it into the cookie. This is done in PHP – which I haven’t really learnt a lot about, but you know what? I was happy to discover that my Javascript training helped me understand the PHP.

Finally, once you have the persistent cookie with the language variable in place, you need to have code on each page so that when a user returns to the site you can get the information out of the cookie and deliver them the appropriate web page. (The phrasing for cookies is usually setting cookies and getting cookies).

After I figured out the issue, I went and explained it to the account manager. Due to inexplicable self esteem issues – I couched my advice in “I think”, and “maybe” and at the end rounded it off with “is that right do you think?”

Actually, I should have been all “Hey, check it out motherfcker! This is how you do it!”.

Because I was right. And they didn’t think I could do it.

Interesting things I learnt while figuring out this problem:

  • You need to set cookies prior to the <html> tag, because you need to do it before any output is sent to the browser (e.g. so in this example, before they are sent any default language page)
  • When investigating the similarities between PHP and JavaScript I learnt this:

“Programs written in JavaScript run in the web browser itself, so if your website has a JavaScript program, the program will be automatically fetched by your visitor’s browser and executed on his/her computer. PHP, on the other hand, runs on the computer where your website is located, that is, on your web host’s computer. After the PHP program does what it needs to do, it sends the result to the visitor’s web browser, which merely displays the results.”

  • I already knew the following, but it is important to remember when changing any cookies, especially on EU sites: You must update the information on your site about the cookies you collect (e.g. on your privacy page).
  • As with any forum, you can’t believe everything you read on StackOverflow, but you can piece things together from all the very helpful community members there. It is an AMAZING resource, although it intimidates me with all the things I don’t know yet. (p.s. you can’t believe everything you read on my site either, obviously).

Other things going on in my learning coding brain

  • Since I am using the codecademy interface so much, in normal email/Word/whatever, whenever I type a “, ( or { – I keep expecting the closing one to be automatically inserted.
  • I am on day 31 of my Codecademy streak


Leave a reply

Understanding WordPress Part 1

So, here I am, going along with all my coding training, thinking I am pretty hot sh!t, because I have this streak going, all these points and badges, and I decide – you know what? This streak needs to be recorded for posterity, maybe I will just start a blog to talk about everything I am learning, and use the site to practice and build heaps of awesome things.

So I toddle off to Zuver and get my domain and hosting ($20 all in! Trace loves a bargain) – and download WordPress into a blog folder. My confidence is still sky-high because I have been using WordPress for a long time for work, and think that soon I am going to have the most super-beautiful blog the world has ever seen.

Well. I have given up on that dream for now. Yes I know how to post and make pages and change settings – but understanding how to customise this thing is doing my head in.

After messing around for a while trying to figure out how to make the theme I really wanted suit what I need it for, I have gone back and decided to use a free, very simple WordPress theme – TwentyTwelve (insinuating that it is soon to be usurped). I’m not even going to put on background images yet. 

The fact that there are tens of thousands of people who are using this thing efficiently and clever-ly is making me feel dumb. So I am going back to basics to try and get a better understanding of what WordPress is. I got this infographic from Yoast - WordPress expert.

Understanding wordpress

Courtesy of Yoast – the WordPress SEO experts. I have been reading Joost de Valk’s blogs for years (don’t let my non-expertness be a bad reflection on his site).

Ok, so let’s have a look-see here:

The Template Files – Header, Footer, Sidebar and Loop

Yep, ok, header, footer and sidebar are the template files which show how your site is displayed. I think I have these under control and know where to change them if I need to. But what is this thing called ‘The Loop’, for the body?

The display of contents of the main area of your site are controlled by individual template files using what’s called ‘the loop’. 

I need a bit more help on this explanation, (ahaha, it is the most basic concept of WordPress and I had never even heard the term used in relation to WordPress before! Confidence!).

Further down in their infographic, they have a deeper explanation, but I am still finding it confusing, so instead I head over to After having a little read, this is how I think the loop works (for anyone else, I am sure the Yoast explanation is better!)

The Loop is PHP code used by WordPress to display posts.

So,it is another php file, which determines the template for how each post looks.

 For example, The Loop displays the following information by default for each post:

It is called the Loop, because it is an if/while loop, and its structure looks something like this.The Loop

First it checks if there are any posts with the have_posts function. If there are posts, then a while loop is executed.

The function the_post takes the current item in the collection of posts to make it available for use inside the iteration of this loop.  Then the template can start showing data for that post (e.g. heading, author, time of post, etc).

The next function, the_content, fetches the content of the post and displays it.

I think that is enough for me to try and digest right now – the main meat of the WordPress template – the header, footer, sidebar and loop (body). If you want more information, the site was very helpful or you might want to read this article from Net Magazine.

Other php Files


The default home page php file shows a loop of your most recent posts, but can be changed in settings->read to have a separate static page as a home page (e.g. ‘Welcome’), and simply link to your blog posts from a menu.


This is the php file used for displaying a single post.


This decides how pages are displayed. So you can make unique elements for pages vs posts. You don’t need to have all your pages look the same, you can have various page templates. So, when making a wordpress site, you could have a template for ‘services pages’ another template for ‘about us’ pages, etc.


This is the file where you can put your own custom code – so if you want to change the theme around a bit more majorly – e.g. extra sidebars or changes to the wp-admin interface.

Other php files to change the look and feel of parts of your WordPress site are archive.php, tag.php, comments.php and category.php.


The stylesheets for your WordPress site-  yep, I get this.



Free plugins made by the WordPress community can enhance your site – e.g. ecommerce plugins or social media plugins.

Custom fields

These are extra fields included in your post/page interface within WP-Admin – in my role I have often seen them used for SEO plugins or javascript includes.


Widgets are the things in your sidebars, and while there are many already included, you can use php or plugins to add more.

The end

Ok, so that’s the end of the Yoast infographic. It’s been helpful, but apart form understanding the idea of ‘The Loop’, I think I had known most of this. What I want to know more about is how to learn how to change and customise it.

I named this post Part 1 without immediate ideas of my next post, just knowing that there will be another.

Maybe I will dive into for lessons or this other site for WP beginners.


Leave a reply

Codecademy 26 Day Streak


I wonder what percentage of  blogs are born of new year’s resolutions?  Not that that is my reason for starting a blog (I already have one for my travels, it languishes). No, my 2013 resolution(I only ever commit to one per year, easier to remember) – is to learn coding/programming and try and do at least some little bit every day.

In relation to that, check out my current streak on Codecademy. I started on January 1st and have done at least a little bit each day. I don’t care too much about points, or badges, but for some reason this streak is having me coming back for more.

I actually started Codecademy last year. 2012 was their ‘Code Year’ and they had a lot of promotion going around about their free course – so much so that I think even the Mayor of NYC signed up. Anyway – coding was something I had been learning bits and pieces of for ages so I thought it would be good to try.

I actually loved their interface, although many of their original drafts of the lessons have since been usurped by better versions. Their jQuery course especially has improved, the first iteration was way too confusing and almost had me quitting, while the new course I found almost too easy.

Doing a bit of Codecademy each day is not hard – all you need to do to keep your streak going is to do one exercise and get one point. In some cases, this could take as little as two minutes, so it is an easy thing to keep up with. I also put an alarm on my phone each day to make sure I don’t lose my streak (overkill? Why do I care about this again?).




Leave a reply