Setup spam filters for WordPress comments

Setting up spam filters filters for wordpress is simple and quick, but requires maintenance over time.

Firstly login to the admin area, goto settings->discussion.

We need to go through and setup some options. Under ‘Default article settings’, leave all settings selected. This means that you can send can receive trackbacks and important part of blogging as this gives feedback and will help with SEO.

Under ‘Other comment settings’, leave all selected. This will mean old comments are closed and limits what is shown by default. Also forcing users to login before comments will remove some simple spam comments but most will get around this simply.

Under ‘E-mail me whenever’ uncheck both options, as you do not need to know when a comments are added. This is something you can do once a week or more.

Under ‘Before a comment appears’ uncheck both options, as again you do not want to be managing the comments as it could be a full time job.

Under ‘Comment Moderation’ moderation change option to 1 or more links.

Now we have opened up the site, we need to start adding some blacklisted words. Anything you put in the box under ‘Comment Moderation’ will hold the comment until you authorise it. Anything you put in the box under ‘Comment Blacklist’ will block the comment completely.

This is where the real work begins. Users you want to block, you need to add in their email and their username they used to signup in either the moderation list or the blacklist. To start with I would add ‘viagra’ in the blacklist unless your blog is related to online an pharmacy. And a good example for adding into the moderation list is ‘insurance’ as this can be somewhere in-between depending on the content of your post.

Over time you need to add more words to each list. You can find some examples by googling ‘wordpress comment blacklist’.

UPDATE: Seems another way of setting up comments is to use a service like disqus who have a free option which should do everything for you.

Posted in wordpress | Leave a comment

IE Heading wrap fix

Quick fix that I have been searching for a while.

I noticed that in IE the headings on my page, h1, h2 etc were not wrapping in the same way as other browsers. In IE as with some other styling issues that crop up you have to explicitly define the value. So white-space: normal should be default right? well not in IE.


h1 {
    position: relative;
    white-space:normal;
}

This is in condition tags in the head of the webpage


<!--[if IE]>
    <link rel="stylesheet" href="iestyle.css" type="text/css" media="screen" />
<![endif]-->

Posted in design | Leave a comment

hspace/vspace Jquery fix for WordPress

Recently I have setup a new WordPress site for a client and the issue of browsers not recognising the hspace and vspace tags for images. I found an easy fix at stackoverflow, just replaces the hspace and vspace tags if it finds them with margin styles.

Just add the following to your header.php file in your chosen theme, or put this into an external file and add using the wp_register_script function in your themes functions.php script.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('img[hspace]').each(function(){
            var pixels = parseInt($(this).attr('hspace'));
            if(isNaN(pixels) || pixels < 1)
                pixels = 0;
            else
                pixels = pixels / 2;
            $(this).css('marginLeft', pixels + 'px')
                .css('marginRight', pixels + 'px')
                .removeAttr('hspace');
        });

        $('img[vspace]').each(function(){
            var pixels = parseInt($(this).attr('vspace'));
            if(isNaN(pixels) || pixels < 1)
                pixels = 0;
            else
                pixels = pixels / 2;
            $(this).css('marginTop', pixels + 'px')
                .css('marginBottom', pixels + 'px')
                .removeAttr('vspace');
        });
    });
</script>
Posted in development, how to | Leave a comment

My 5 Top tips for Freelancers

Having taken the plunge and work for myself from home I have already got some tips for other freelancers starting out or thinking about working for themselves. I want to talk about general tips that could probably help people working in different industries.

Get Fit

Being sat infront of my laptop all day long has not been great for my health. I have always worked in offices so getting exercise has been important for me. Since starting working for myself the gym has taken a back seat to whatever I wanted to get finished. So go use that gym membership and start getting fit. You will have more energy, wake up fresher and generally will get more done during a day.

Take a two hour lunch break

I have worked the normal 9 to 5 for many years so I am used to a set routine. Do not feel guilty if you take a long lunch break. When I started I tried to do a 9 to 5 have an hour for lunch and stay focused all day long, this does not work. If I spent a long time at lunch doing something I would try to make up the time and feel bad if I could not. So if you have to goto the dentist, get some shopping done don’t feel guilty.

Scream out loud

A number of bloggers I have read have said this before me, working for yourself is an emotional rollercoaster. One week I was talking to several clients doing lots of work, the next I would talk to no one and have no work. Other bloggers have said it takes a certain type of person to freelance or run a start-up. I would say if you gotta go cry in the corner or run down the street screaming do so. I find chatting to someone in person or on the phone helps, do what you have to so you don’t feel isolated.

Go get a coffee

Working in Norwich city centre I have been used to having loads of shops and cafe’s right next to you. So a good way to get a break is to go grab a coffee from the nearest chain coffee shop. I have found this should not change while you work from home. Its a great way to take a break and get some fresh air. Even better if you can find a local shop whom can get your trade rather than a chain one and that local bussiness owner might be your next new customer.

Finish your shift

While working for yourself means you can set your own hours and shifts, I think it should be that “your” 9 to 5. I have found working for myself means that when I get working on a project I only stop for food or sleep. This has not been good for me or my clients. So I have what I like to think of as ideal working hours. These do change and I might finish earlier or later, but I do finish for the day. You should actually finish work for the day and not find out that its suddenly 2am and you wonder where the time went.

So find out what works for you to make sure you get the job done. And be prepared to make changes today not tomorrow.

Posted in business planning, productivity | Leave a comment

Style inline custom WordPress menus

Now WordPress has reached version 3 there are loads of fantastic new features. One of which is the new custom menus feature with the ability to control different menus directly in your template. To start edit your themes functions.php file, if you don’t have one just add a functions.php into wp-content/themes/your-theme-name/ folder.

Add the following code into the file :-

add_action('init', 'register_custom_menus');

function register_custom_menus() {
	register_nav_menu('main', __('main'));
}

You should now sort out your menu in WordPress’s backend. Easy to setup just goto Appearance->Menus. Select from pages and click to add, the menu can then be sorted by dragging. Submenus can be added by dragging menu to the right slightly.

Now if you go back to editing your theme, add the following where you want the menu to appear. I normally do this in the header.php so it appears on each page.

<?php wp_nav_menu(array('menu' => 'main', 'menu_class' => 'menu-main')); ?>

You will notice the problem now is you can see all the menu. So what we want is a more conventional menu that only shows child pages from the current page. I have listed the full css I have used on a different site at the bottom on the page, but here are some highlights to notice.

Most important piece of CSS, firstly you need to hide all submenus.

#menu-main li ul.sub-menu {
    visibility: hidden;
}

Now show any children of the current page or if the current page is a child of another page show other children with the same parent.

#menu-main li.current-menu-item ul.sub-menu,
#menu-main li.current-menu-parent ul.sub-menu {
    visibility: visible;
}

As you can see without the use of javascript or flash we have a dynamic menu. Below is the menu CSS for a site I have recently completed.

.menu-main-container {
/* feel free to ignore this but these widths below were developed while I was doing a grid960 site */
    width: 940px;
    margin: 0 0 5px;
}

#menu-main {
    margin: 0;
    padding: 0;
    z-index: 99;
    position: absolute;
    top: 77px;
    left: 180px;
}

#menu-main li {
    float: left;
    list-style: none;
    font-size: 12px;
    z-index: 99;
    margin: 0;
    padding: 0;
}

/* First level menu style */
#menu-main li a {
    display: block;
    padding: 2px 0;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    z-index: 99;
    margin: 0;

    /* replace with menu off styles */
    width: 75px;
    line-height: 27px;
    color: #eb0088;
    background: url('images/menu-off.gif') no-repeat;
}

/* First level menu on styles */
#menu-main .current_page_item a {
    /* replace with menu on styles e.g. backgrounds/colours */
    background: url('images/menu-on.gif') no-repeat;
}

/* First level menu on styles */
#menu-main .current-menu-ancestor A:link,
#menu-main .current-menu-ancestor A:active,
#menu-main .current-menu-ancestor A:visited,
#menu-main .current-menu-ancestor A:hover {
    /* replace with background/colours for menu on style */
    background: url('images/menu-on.gif') no-repeat;
}

/* First level menu on hover styles */
#menu-main li a:hover {
    z-index: 99;
    /* replace with background/colours for hover styles */
    color: #eb0088;
    background: url('images/menu-on.gif') no-repeat;
}

/* Sub menu styles
#menu-main li ul.sub-menu {
    position: absolute;
    visibility: hidden;
    z-index: 99;

    /* replace with background/colours for submenu, also fix position */
    width: 940px;
    left: -180px;
    top: 27px;
    background: url('images/sub-menu-back.gif') top left;
}

#menu-main li ul.sub-menu li {
    float: none;
    display: inline;
    z-index: 99;
    background-image: none;
}

/* Submenu styles */
#menu-main li ul.sub-menu li a {
    width: auto;
    z-index: 99;
    text-align: left;
    display: inline;

    /* replace with your current submenu styles */
    background: url('images/sub-menu-hover.png') no-repeat left 13px;
    line-height: 23px;
    margin: 0 10px 0;
    padding: 10px 10px 10px 10px;
    color: #d7d6d6;
}

/* submenu hover styles */
#menu-main li ul.sub-menu li a:hover {
    z-index: 99;
    background-image: none;

    /* Replace with submenu hover styles, I added #fff here to highlight onMouseOver */
    line-height: 23px;
    color: #fff;
}

.current-menu-item li {
    margin: 0;
    padding: 0;
}

/* Submenu - Now we have styled most of submenu show current pages submenu */
#menu-main li.current-menu-item ul.sub-menu,
#menu-main li.current-menu-parent ul.sub-menu {
    visibility: visible;
}

/* Submenu styles - This is style for the submenu link if it is the current page */
#menu-main li.current-menu-parent ul.sub-menu li.current-menu-item A:link,
#menu-main li.current-menu-parent ul.sub-menu li.current-menu-item A:active,
#menu-main li.current-menu-parent ul.sub-menu li.current-menu-item A:hover,
#menu-main li.current-menu-parent ul.sub-menu li.current-menu-item A:visited {
    /* Styles here do not matter too much #fff again to highlight colour */
    color: #fff;
    background-image: none;
}

/* Submenu styles - This is the style for the current pages submenu */
#menu-main li.current-menu-parent ul.sub-menu li A:link,
#menu-main li.current-menu-parent ul.sub-menu li A:active,
#menu-main li.current-menu-parent ul.sub-menu li A:visited {
    /* Styles here not too important just stick to colour/background etc */
    background: url('images/sub-menu-hover.png') no-repeat left 13px;
}

/* Submenu styles - Style for submenu onMouseOver */
#menu-main li.current-menu-parent ul.sub-menu li A:hover {
    /* Styles here not too important just stick to colour/background again */
    background: none;
}

Any comments or suggestions for future how-tos please contact me.

Posted in design, how to | Leave a comment