Add HTML, JavaScript or Google Analytics code to the footer of your WordPress site

It is not very complicated to add HTML, JavaScript or Google Analytics code to the footer of your WordPress site.

Open your theme’s functions.php file (if you don’t know where/what that is, you might be better off not doing this… or if you are persistent, google it first so you have an idea of what you are doing).

Somewhere after the <?php tag in that file, enter the following code:

function add_custom_footer_stuff() {
add_action('wp_footer', 'add_custom_footer_stuff');




Super simple code to show full image over content with jQuery

Often I just want to make a thumbnail clickable and show it as an overlay on top of the other content. Of course there are loads of plugins but sometimes it’s just more fuzz to install and setup those than just creating it yourself. So here is the code I used:

HTML code, for instance:

<img alt="" src="" id="mainImage">

Javascript code:

<script type="text/css">
$("#mainImage").click(function() {
 var fullImageName = $(this).attr("src").replace("/std/", "/");
 $("<div style='background: rgba(255,255,255,0.7); width: 100%; height: 100%; position: absolute; top: 0; left: 0; z-index: 10000; text-align: center'>"+
 "<h1 style='color: #555;background:#fff; width: 100%; height: 100px; margin: 0 auto; padding: 20px 0;'>Click here to close</h1>"+
 "<img style='' src='"+fullImageName+"'  />"+
 "</div>").appendTo("body").on("click", function() {

Then you may of course substitute the image ids etc to your own needs.

Matching domain names using JavaScript RegExp

This is a Regular Expression that I used to check validity for a domain entered by a user. It covers the top domains which the particular service covered and you should change it for your own top domains.

If you need a RegExp that matches all valid domains, including all top domains and all subdomains, there is a good attempt (no support for special characters such as åäö) here.

Here is the code:

var domainPattern = new RegExp("^[a-z](-?[a-z0-9]+)*\.(se|com|net|biz|org|es||dk|info|eu|mobi|name|nu)$");
if (!domainPattern.test(domainField.value.toLowerCase())) {
// Not ok
else {
// Ok

Hope it’s of any use to someone!