How to add an EU Cookie Consent popup to your web site

Cookie Consent / IdiocyCookie Consent laws: you have surely seen them.

You go to a site, and you get a popup or bar at the top of the site that says, “We use cookies, blah blah blah…”

There is usually a “Learn more” link, and sometimes a way to accept or reject that site’s use of cookies.

The reason for this is a very stupid law implemented in the European Union that is supposed to protect people from… well, actually, it doesn’t protect anyone from anything. Okay, technically, it protects you from your sanity.

Especially if you use Google Adsense to put ads on your web site, you probably have received an e-mail from them telling you that you must have a Cookie Consent thingie on your site by the end of September 2015 in order to comply with yet another EU cookie law.

Right, so, how do you add cookie consent to your site – quickly and easily?

Read more…

Understanding Embed Codes

Embed CodesYou have probably encountered embed codes before, but they may seem like a bit of a mystery.

An embed code is, in short, a bit of HTML that allows you to embed part of another web site on your own – like a YouTube video, for example.

Embed codes come in two general flavors these days, and each has its strengths and weaknesses.

So, how do embed codes work? Why are some hugemongous, and others teeny-tiny? Are iframe tags really the spawn of the devil?

Read on!

Read more…

JavaScript Fun: Looping with a Delay

JavaScript is Awesome!If you’ve ever programmed something in JavaScript, you most likely ran into a situation where you needed a delay.

Normally, we do this with setTimeout().

For repeatedly calling some function every X milliseconds, one would normally use setInterval().

Well, that’s fine. But what if you want to so something 10 times, and delay 3 seconds between iterations?

The solution is not as obvious as it appears…

But it is simple!

Read more…

Adding Videos, JavaScript, and Other Goodies to Posts in WordPress MU

Some of you may recall my earlier post Adding JavaScript to WordPress Posts without a Plugin. In that post, I talked about how to add JavaScript for, say, embedding a video without having WordPress “sanitize” your code… and without any plugins!

WordPress MU, the version of WordPress that allows multiple blogs to be run under one WP installation, uses a different content sanitizer. In fact, it’s so seriously anal that it blows away not only JavaScript, but all kinds of other HTML tags in your posts that the regular WP leaves untouched! Bad juju.

In the case of WP MU, the best solution that I could find does include a plugin – but you can write it yourself in about 10 seconds. In writing the plugin yourself, you will also know how to maintain it yourself. Even if you don’t know much about PHP, this one’s a piece of cake!

So, here’s how to convince WordPress MU to play nice with the HTML in your posts…

Read more…

jQuery AJAX Form Submit for Dummies

AJAX Form using jQuerySo you’ve decided to be supercool and use jQuery. That was a wise decision you made, because jQuery totally rocks. Especially in Rails apps, jQuery makes life a LOT simpler. Yes, you have to learn some JavaScript and some quasi-new syntax, but it’s still seriously powerful and convenient.

There’s only one problem: if you’re like me (i.e. JavaScript-impaired), you just couldn’t get your forms to submit via an AJAX call.

You’ve probably heard of something called the jQuery Form Plugin. It’s a bit overwhelming looking at all the options and trying to extract just the functionality you need if you aren’t a JS Jedi, though. And so, without further ado, I present to you jQuery Form Submission for Dummies!

Read more…

Adding JavaScript to WordPress Posts Without a Plugin

JavaScript in WordPressIf you have installed your own WordPress blog on your server, you may want to include some JavaScript goodness from time to time.

The bad news is that WordPress likes to screw around with tags when using the WYSIWYG post editor. That makes it kind of hard to, say, embed a video in one of your posts.

The good news is that there is a very easy way to embed any kind of JavaScript in your posts without the need to install any plugins, or change any configuration settings. And it works beautifully with the WYSIWYG editor…
Read more…

SyntaxHighlighter: Prevent #{var} in a Ruby String from Being Parsed as a Comment

WordPressWordPress is a seriously popular blogging platform, primarily because it simply rocks. In fact, this here blog uses WordPress.

Since I generally write posts about programming issues, I needed a good plugin for automagically highlighting code segments. I ended up choosing SyntaxHighlighter by Viper007Bond.

While it generally kicks butt, there is one little bug that is particularly annoying for those of us who post snippets of Ruby code: including a variable in a string like 'this is a #{color} string' causes SyntaxHighlighter to make everything after the “#” into a comment, which it wraps down to the following line.

That simply won’t do…

Read more…