How To: Prevent Google From Indexing Your Images

For most of us, traffic is the driving force behind our blogs and motivation to blog. Therefore, it may seem silly to think that you would want to prevent a lot of potential traffic from Google’s image search.

However, some bloggers like to post personal pictures, or custom make their pictures and don’t want others to take them when possible. If you fit into this category, you can easily prevent Google from indexing your pictures by placing the following code into your blog’s header file above the < /head > tag:

<meta name="robots" content="noimageindex">

If your site has a problem with people taking your content (including the pictures), then there is a chance Google will still index them when they index that person’s website. Another route you can take is to place images into a folder then add a disallow to your Robots.txt file. For WordPress users, this is fairly easy as by default, we already have pictures in either our Images folder of our theme, or the uploads folder (unless you’ve assigned a custom path for your images). You can add something like the following to your Robots.txt file:

User-agent: *
Disallow: /images/


User-agent: *
Disallow: /uploads/

  • Leave a Comment
  • How To: Alternating Your Post Background Colors

    Comments Off on How To: Alternating Your Post Background Colors

    One thing I’ve always loved to do is set up my blogs comments to display alternating background colors (although ironically I have not done so for this site yet). I’ve always felt that this helps give the comments a little more separation from each other and improve the overall look of the blog.

    Because WordPress is full of loops (homepage, category, tag, etc.), this same theory can truly be applied all over your blog. David of CyberCoder posted yesterday a great hack to alternate the background of your blog posts. Here are the steps you need to take:

    Create a loop counter. Right before the Loop begins set a variable to zero.

    if (have_posts()) : ?>

    At this point I would want the Background Color to change, insert code to test for an even number post, and if this is true, add an inline CSS style for the background that would override the stylesheet.

    <?php if ($odd = $x%2){?>
    <div style=”background-color:#404040;padding:10px 0px 10px 10px;”>
    <?php }?>

    Then, where the background color should return to the original state, run the same test for the even numbered post and close the div tag set by the Inline Style.

    <?php if( $odd = $x%2 ){?>
    <?php }?>

    The final step is to add 1 to the counter for each post, which is done at the end of the loop.

    endwhile; ?>

    Thanks for sharing this trick David!

  • Leave a Comment
  • How To: Hiding Your Sub-Categories in WordPress

    I recently got an e-mail from a reader wanting to know how to hide their sub-categories in WordPress. If you use WordPress 2.1 or newer, this is actually really easy to do.

    All you need to do is open your stylesheet and add the following anywhere:

    .children {

    You can also style the children accordingly this way if you’d like!

  • Leave a Comment
  • WordPress Hack: Using WordPress Conditional Tags

    Have you ever noticed how some pages on blogs behave different than on other pages? One of the most under-utilised features of WordPress is the wide variety of conditional tags available in WordPress. Through the use of conditional tags, you can instruct certain plugins, pictures, or code to only appear on designated pages.

    Recently I ran across a post by the Undersigned explaining Conditional Tags in WordPress, which appears was written in 2006 but is still valid with current versions of WordPress.

    Here is a list of the conditional tags available:

    • is_home()
    • is_single()
    • is_page()
    • is_category()
    • is_author()
    • is_date()
    • is_year()
    • is_month()
    • is_day()
    • is_time()
    • is_archive()
    • is_search()
    • is_paged()
    • is_404()

    One of my favorite places to use conditional tags is in the post meta area. For example, on most pages I want the comments button to display, but I don’t need it to appear on the single page because the comments are displayed on that page. At the same time, I like having an edit button on the single page, but I don’t need it on any other pages.

    Here is the code I use for the above example on one of my sites:

    <?php if (is_single()){ ?> <?php edit_post_link(__("*Edit*"), ''); ?> <?php } else { ?> | <?php comments_popup_link('0 comments', '1 comment', '% comments'); ?> <?php } ?>

    The bold code is the conditional tags I’ve set up.  You can see from the above code that I am telling WordPress to only display an Edit button on single pages, and on all other pages display the comments link.

    What other good uses have you found for conditional tags?

  • Leave a Comment
  • How To: Displaying Content Only For The Admin To See

    Roughly four months ago I talked a bit about how to set up your blog so only the admin can see an edit button on blog posts. For whatever reason, I’ve always set this up on each of my websites and really get a lot of use out of it. Much along those same lines, Michael of WPCandy has written a post explaining how to display content so only the admin can view it. This goes well beyond the edit button and allows you to setup just about anything to display for the admin.

    In hist post, Michael provides some code that looks at the user id to determine if the user has admin privileges and then displays whatever you tell it to for that user. Here is the code:

    <?php global $user_ID; if( $user_ID ) : ?>
    <?php if( current_user_can('level_10') ) : ?>
    <a href="">Stats</a>
    <?php else : ?>

    <?php endif; ?>
    <?php endif; ?>

    If you run a multi-author blog and would like to make this stuff available to editors, authors, contributors, and more, you can easily adjust the user level to determine who sees your display.

    Great find Michael!

  • Leave a Comment
  • How To: Display the Recent Posts of Specific Categories

    Most WordPress themes, by default, come with Recent Posts displayed automatically. Depending on the type of blog you run, it is possible that you would prefer to display Recent Posts per category. If this is the case, here is what you need to do to only display recent posts for specific categories.

    First, you’ll want to find your Recent Posts code, which is usually found in the sidebar. It will look something like this:

    <h2>Recent Posts</h2>
    <?php get_archives('postbypost', 10); ?>

    As always, make sure you have a backup of the file in question before making any changes. You’ll then want to replace the above code with the following code:

    <?php $recent = new WP_Query("cat=1&showposts=10"); while($recent->have_posts()) : $recent->the_post();?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php the_title(); ?>
    <?php endwhile; ?>

    Where is says cat=1, you’ll want to insert the number assigned to the category that you want to display the posts from. You can find this from your Manage -> Categories page. You can also adjust the number of posts to be displayed where it says showposts=10.

    This could be useful to someone who wants to display the most recent few posts from a few different categories in their sidebar.

    [via ReadyWPThemes]

  • Leave a Comment
  • How To: Blocking Your WordPress Categories and Archives From Google

    We all know that duplicate content can be a problem. People copy your work, re-post it on their website, then you both are penalized for duplicate content! Unfortunately, there isn’t much that can be done about that, but did you know that often blogs have duplicate content within their own blog? The biggest culprit for duplicate internal content is your archives page, which is usually used for categories and monthly archives. Unless you only display partial posts in your archives, you’ll want to make sure Google doesn’t index it. If you aren’t handy with Robots.txt, you can instead use this code to easily tell Google not to index your archive.php page.

    <?php if(is_archive()){ ?><meta name="robots" content="noindex"><?php } ?>

    You’ll want to grab that code and paste it anywhere in the header of your theme above the closing of the head tag. That way, Google will not index these, and search engines won’t refer traffic to your archive pages instead of your single post pages.

  • Leave a Comment
  • WordPress Blogroll Code: Separating Your Categories

    I had a reader request for some help with their blogroll recently. The WordPress blogroll has gone through many changes over the past year, and a lot of the WordPress themes authors out there didn’t update their themes with the new code used to call the blogroll.

    The old code still works, but it doesn’t let you take advantage of the new blogroll capabilities.  If you have set up your blogroll with different categories, but noticed that all of them display under a single category, it is probably because your blog’s theme is still using the original code that didn’t allow for much configuration. You’ll probably find something like this:

    <?php get_links()' ?>


    <?php get_links_list()' ?>

    If you want a more configurable code, you will want to use something like the following:

    <?php wp_list_bookmarks('categorize=1&before=<li>&title_before=<h2>&title_after=</h2>&category_before=</n>&category_before=</n>&after=</li>&orderby=url'); ?>

    This code will display your blogroll, but will let you have separate lists for your different blogroll categories. I’ve customized it to display the category title as a Header 2 and use bullet points to display the content, but you can do a variety of things. For more customization options, you’ll want to check out the WordPress List Bookmarks page and adjust the code as needed.

  • Leave a Comment
  • How To: Converting The Author Display To Link To The Author

    If you are setting up a WordPress blog to work with a variety of authors, it is probably a good idea to also set up the author display to actually be a link to the bloggers website.

    For whatever reason, many themes are created to simply display the author’s name using text by default instead of converting it to a link to the author’s website. Fortunately, this is an easy change to make with a minimal amount of coding adjustments required.

    Here is what you need to do. When editing your theme, you’ll want to look for the following code:

    <?php the_author() ?>

    Remove that code and replace it with the following:

    <?php the_author_link(); ?>

    Now test it out! It will automatically display a link to the author’s site, as specified in the users profile.

  • Leave a Comment
  • Code: Adding Recent Comments To Your WordPress Theme

    By default, most WordPress themes display Recent Comments in some form or another. Unfortunately, it isn’t usually very user-friendly, so it will often get removed.

    Until now, most of your other options required the use of a WordPress plugin, but today I ran across a great code snippet you can use to display recent comments in a useful format. I just tested it out on my test site and it looks good. Here is the code you will want to paste into your theme’s sidebar:

    <h2>Recent Comments</h2>
    global $wpdb;
    $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
    comment_post_ID, comment_author, comment_date_gmt, comment_approved,
    SUBSTRING(comment_content,1,30) AS com_excerpt
    FROM $wpdb->comments
    LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
    WHERE comment_approved = '1' AND comment_type = '' AND
    post_password = ''
    ORDER BY comment_date_gmt DESC
    LIMIT 10";
    $comments = $wpdb->get_results($sql);
    $output = $pre_HTML;
    $output .= "n<ul>";
    foreach ($comments as $comment) {
    $output .= "n<li>".strip_tags($comment->comment_author)
    .":" . "<a href="" . get_permalink($comment->ID) .
    "#comment-" . $comment->comment_ID . "" title="on " .
    $comment->post_title . "">" . strip_tags($comment->com_excerpt)
    $output .= "n</ul>";
    $output .= $post_HTML;
    echo $output;?>

  • Leave a Comment