How To: Adding a Print This Button to Your Theme

If you ever visit our actual website, you’ve probably noticed the “Print This” button that we display below each post.  Depending on the type of website or blog you are running, having a button like this may be a good fit for your blog.  I’ve found it to be good to have this button available to readers for any type of website that offers tutorials, recipes, guides, or pretty much anything that might require a visitor to print something you’ve written.

If you think you’d like to offer your readers the option to print something on your blog, here is the code I use on my blogs (uses Javascript):

<a href="javascript:window.print()" rel="nofollow">Print This!</a></span>

It prints the page you are on, so it is probably best to use it mostly on post and pages.  If you place it on the blog’s homepage, it will print the entire homepage, not just that post. 

  • Leave a Comment
  • Tips To Deal With WordPress Content Theft

    Yesterday I wrote a post titled When Has Stealing Content Gone to Far?   At the time of publishing that post, I wasn’t really sure how it would be received because of the subject matter.   So far all feedback has been pretty positive, so I decided to write a quick follow up post talking about how to deal with getting your content stolen.  Thanks to Laurence for the idea.

    As most people should know, when you publish content, pictures, or whatever else on the internet, there is always some risk that things will get scraped or stolen completely from your website/blog.  Despite everything falling under copyright protection, people sometimes get away with it because it is often difficult to enforce. 

    So, what can do you to deal with content theft?  Here are two things readers suggested that may help:

    1. Terms and Conditions – Create a clear terms and condition policy that is findable on your website.   It may not help, but it certainly can’t hurt anything.   Throw it in the footer of your blog or somewhere that it is accessible. 
    2. Use Internal Links in your Posts – In addition to the SEO benefits of working on your internal linking structure, scraped and sometimes stolen content will often include these links back to your website.  

    Hopefully those methods will help avoid this in the future, but what can you do when your content has already been stolen? 

    1. Contact the Offender – Depending on the situation, some sites may have a contact form or some way to contact the thief.   You can also try checking the domain whois records.  This is a good way to request they delete your stolen content and stop stealing your content in the future.   Though most know they are doing so, a few might not be aware that this is illegal.
    2. Take Action Against the Offender – If the first option doesn’t yield any results or there is no way to contact the owner, there are two ways to take action against the thief.   If they use Google AdSense to monetize the site (most do), you can report them to Google by clicking on the “Ads by Google” link in the lower right corner of the AdSense box and provide them feedback.  I believe stolen content is actually one of the default options you can check.   The other thing you can do is contact the hosting company and let them know they are hosting websites that are doing illegal practices.  I’ve heard of people have some success going this route, so it is a great last resort. 

    So, that is what I have.   What do you do to deal with scrapers and content thiefs?

    P.S.  Ironically enough, unless there is some sort of screening process that I’m not aware of, this post will be scraped at least 3 times shortly after publication.   Am I the only one that finds humor in that?

  • Leave a Comment
  • How To: Display Adsense On Your First Post Within The Loop

    In this guide you’ll learn how to display Adsense on just your first post within the Loop. Sure, there may be plugins that will do this for you. This guide, however, will use code examples to accomplish the same thing by editing your WordPress theme.

    The first step is to open up your index.php file in your theme editor. Find the following line:

    <?php if(have_posts()) : ?>

    Just above that, insert the following like this:

    <?php $i = 1; ?>
    <?php if(have_posts()) : ?>

    Now, scroll down a bit until you find this line:

    <?php endwhile; ?>

    Insert the following above it, like so:

    <?php $i++; ?>
    <?php endwhile; ?>

    The final step is to insert your AdSense code. Locate where exactly you’d like it within the Loop, and place it between a conditional tag like this:

    <?php if ($i == 1) { ?> [YOUR ADSENSE CODE HERE] <?php } ?>

    And that’s all you have to do. You can be creative with this code as well. You could add a certain css style class to the top post in your Loop. It doesn’t even have to be the first either, as you can just change the number in $i == 1 to whatever you want. This same method can be used in other archive templates such as archive.php.

  • Leave a Comment
  • How To: Adding the Post Authors Gravatar To Their Individual Posts

    One thing I am really excited about is that Gravatars are really starting to gain popularity now that Automattic has purchased and is supporting them. And now that support is built right into WordPress, it opens up a lot of options for WordPress users.

    The most common place you’ll find a Gravatar is usually with an individual comment to help comments stand out.  Another place you will sometimes see them is in the sidebar, like we have it setup here at Hack WordPress.   One thing, however, that people are slowly coming around to is using Gravatars with blog posts to identify the author of the post. This is something that is a great idea for a multi-author blog and something I’ve considered doing on this website.

    So, how would you go about setting up Gravatars to display with each individual post? Over at ThemeShaper, Ian Stewart recently shared an easy way to do this. You just need the following code:

    <?php echo get_avatar( get_the_author_email(), '64' ); ?>

    When used, WordPress will match up the e-mail address associated with the post author to determine what Gravatar to use. The 64 is the size (pixels) of the Gravatar.

    Great find Ian!

  • Leave a Comment
  • How To: Make your WordPress Search Results Unlimited

    Sometimes you may not want your search results to be limited by the confines of the standard WordPress Loop. This is a quick code hack to allow a search to return unlimited results, altering the standard WordPress Loop by using a custom query. You can do this in a few different ways. If you have a search template, in search.php you can simple add the following line of code above your Loop.

    Find:

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    Add:

    <?php $posts=query_posts($query_string . '&posts_per_page=-1'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    Make sure you put this code in your search.php only, unless you want unlimited posts on your index or archive pages. The -1 you see can be changed to any positive integer to limit the posts to a number you choose as well.

    If you don’t have a search.php in your theme, the next level down in the Template Hierarchy is your Main Index Template, or index.php. You can use a conditional tag for the same effect.

    For this we’ll use the same code as above, except wrap it in the is_search() conditional tag, like so:

    <?php if (is_search()) { $posts=query_posts($query_string . '&posts_per_page=-1'); } ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    You can use this technique to change the standard Loop limitations of archives, categories, tag pages, and even your main index template – but it would probably be easier to simply change your reading settings for that.

  • Leave a Comment
  • How To: Creating a Custom Page Template

    Sometimes creating a page within WordPress can be frustrating because it reformats the post and will sometimes break links or cause things not to display correctly. It can also be difficult to display videos or buttons within a page if you use the rich text editor built into WordPress.

    One thing I typically do in these situations is to create a custom page template for certain pages where I need more control over how it displays. One example of this is my advertising page which was created using this method. I wanted to use Paypal buttons for each type of advertisement, and I wasn’t able to do this within the rich text editor that WordPress offers.

    So, here is what you need to do. As a quick note, you will need some very basic HTML coding knowledge to write your page by hand, and you will want to make a backup of your theme before attempting this for the first time.

    What I did was make a copy of the page.php file within my theme. That is because WordPress uses the page.php file when creating your themes pages. Rename the copy whatever you want, as long as it isn’t already in use (I just went with advertise.php in my situation). Now you will need to name the PHP file. Once that is done, go to the middle of the PHP file you’ve created and delete out the content code, which usually looks something like this:

    <?php the_content(__('[Read more]'));?>

    This code might vary a little based upon the theme you are using, so it may not appear exactly like this. Now, you’ll want to paste the text/code you want to use on your custom page. Once you’ve got it how you want it, you’ll want to upload it to your site.

    WordPress Page TemplateThe next thing you need to do is to create a new page in your WordPress dashboard like you normally would. Once you’ve created a title, leave the rich text editor blank and go to the Page Template drop-down box in the right menu. Locate the named page you created earlier in the drop-down menu and select it. Now publish your page.

    You’re done! Go check your site to see how it looks and make adjustments as needed.

    Hopefully I explained this well enough. If you have any questions, please post them below and I’ll do my best to answer them, or will update the post accordingly.

  • Leave a Comment
  • How To: Assigning a Name to Your PHP Files

    By default, WordPress displays your php files by whatever the file name is. That means if you name your file wordpress.php, that is how it will show in your WordPress editor. When working with page templates, or if you just want to keep your files a little more organized, you’ll probably want to give your templates names.

    Here is all you need to do. Paste the following code at the top of the file:

    <?php
    /*
    Template Name: WordPress PHP
    */
    ?>

    Now change WordPress PHP to be the name you want to use. Easy enough, right?  Tomorrow I’ll be posting a little more about page templates!

  • Leave a Comment
  • How To: Switching Your WordPress Blog’s Permalink Stucture

    As a follow up to yesterday’s post about WordPress permalink structure (where a good discussion took place in the comments), I decided today that I would dedicate a post to showing you how to switch your blog’s permalink structure without creating any invalid URL’s.

    The easiest way to accomplish this is to grab the Permalink Redirect plugin (my plugin review here) and activate it. Once activated, when you go into the Settings panel you should find a new tab called Permalink Redirect. Scroll down to the bottom of the page and you should see this:

    In the old permalink structures box, you can paste your current permalink structure there (depending on which you choose, something like /%year%/%monthnum%/%day%/%postname%/). If you are unsure what exactly to type, please refer to the permalink page on the WordPress Codex.

    Now save and go to the Permalinks tab. Select the custom field and type /%postname%/, then save.

    Now go to an old URL and it should automatically redirect you to the same post’s new URL.   The search engines will see the 301 redirect and update accordingly!

    Any questions? Feel free to comment below!

    Update: I believe the plugin has changed since this was written.  If you are comfortable updating your .htaccess file, you can instead redirect all your links to the new /%postname%/ url by adding the following:

    RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://www.domain.com/$4

  • Leave a Comment
  • How To: Setting Up Your WordPress Permalink Structure

    One of the great things about using WordPress is the built-in SEO advantages that this software gives you over building static pages or other blogging software. You have an advantage from the start over others not using WordPress! With that said, there are a lot of SEO techniques that need to be set up or applied by the user. The permalink structure is one of these that you can easily set up when creating your blog and then forget about it.

    By default, your WordPress Dashboard gives you a 3 choices to choose from. The default permalink structure is a terrible option from an SEO standpoint and the other two aren’t bad, but they aren’t your best option. According to Matt Cutts at WordCamp 2007 (Matt is the lead guy for the Google Search team), the best permalink structure you can use is just the post title with hyphens. According to Matt:

    • Don’t put your blog at the root of your domain.
    • Name your directory “blog” instead of “WordPress”.
    • In URLs, no spaces are worst, underscore are better, dashes or hyphens are best.
    • Use alt tags on images: not only is it good accessibility, it is good SEO.
    • Include keywords naturally in your posts.
    • Make your post dates easy to find.
    • Check your blog on a cell phone and/or iPhone.
    • Use partial-text feeds if you want more page views; use full-text feeds if you want more loyal readers.
    • Blogs should do standard pings.
    • Standardize backlinks (don’t mix and match www with non-www).
    • Use a permanent redirect (301) when moving to a new host.
    • Don’t include the post date in your URL.

    For WordPress users, this is easy to set up. Go into your blog’s Options panel and click on the Permalinks tab. You should see the following:

    WordPress Permalink Structure

    Click the custom radio button and type /%postname%/ into the field. This is the most ideal setup for your WordPress blog.

    If you already have an established blog using another structure, you can easily use the Permalink Redirect WordPress plugin to redirect your posts to the new structure.

  • Leave a Comment
  • How To: Moving from WordPress.com to WordPress.org

    Comments Off on How To: Moving from WordPress.com to WordPress.org

    WordPress.com is a wonderful and free way for people to begin blogging, but it is only natural for a blogger to eventually “outgrow” it and make the move to a self-hosted WordPress blog. Eventually the draw of being able to monetize your blog, combined with the lure of WordPress themes and WordPress plugins can be to much!

    For those making the switch, it can be a period of adjustment as the blogger transitions from having everything done for them to having to do everything themselves. Michael Martine has written a great post walking people through making the move from WordPress.com to WordPress.org. If you are still on WordPress.com, I recommend you click over to check it out!

  • Leave a Comment