How To: Add a Twitter Link to Your WordPress Blog

Twitter is all the rage these days and it doesn’t seem like it will be going anywhere any time soon.  With that said, it often surprises me that many WordPress blog owners  don’t offer a convenient way for their readers to retweet their content.  Anyone can grab a Twitter WordPress plugin to tweet their new content as it is published, but what about your older content?

Rather than passing up all that potential traffic, I’ve found that offering a link somewhere within your post (optimally at the bottom of each post) is a great way to help your readers and incoming search engine traffic to promote your content for you.  When people find great content they like to share it with others, so why not make it easy for them?

Not only is adding a “Tweet This!” link a great choice, but it is really easy to do.  Chances are if you do a search on Google for code to use you’ll find something like the following:

<a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank">Tweet This!</a>

This code works just fine, but is not the most optimal solution in my opinion.  Depending on the permalink structure your WordPress blog uses, combined with the length of your domain name, it may be difficult to fit the link into a 140 character tweet.  It also doesn’t leave room for the person to add their own comments to the tweet.

As a proposed solution, I recommend using some WordPress code like the following:

<a href="http://twitter.com/home?status=RT @HackWordPress <?php the_title ();?> <?php echo get_settings('home'); ?>/?p=<?php the_ID(); ?>">Tweet This</a>

This code will automatically insert the “RT” and your Twitter account name (the above example uses our Twitter account, @HackWordPress) then use the ID form of your post with the tweet.  When people click the link in the tweet, they will then be redirected to the actual post using your blog’s selected permalink structure, making a convenient and typically short URL.

Have you integrated Twitter into your WordPress blog? Share your strategies in the comments!

  • Leave a Comment
  • Separating Trackbacks from Comments in WordPress 2.7+

    Back when WordPress 2.7 was released, the WordPress team introduced a completely revamped comment form that included integration of threaded comments into the core software, introducing some dramatic changes with how comments are handled.   Unfortunately, this change broke one of the most popular comment hacks, separating trackbacks from comments.

    Since then, several people have stepped up and shared some great hacks for separating trackbacks from comment in WordPress 2.7 or newer blogs .  So far the best guide I’ve found came from Sivel.net, which can be viewed here.  Click over and follow those steps get everything separated.

    Note: The above guide is only for people using WordPress 2.7 or newer installations.  For people using WordPress 2.6 or earlier, you’ll want to use this tutorial.

    Once you’ve got the comments successfully separated from the trackbacks, there are a couple additional tweaks you may want to do to clean up how things look (it really depends on preference I suppose).   The first is to clean up your trackbacks/pingbacks by only displaying the title instead of an excerpt and everything else.   In order to do this, you’ll need to find the following code in your comments.php file:

    <ol>
    <?php wp_list_comments('type=pings'); ?>

    Now replace that code with the following:

    <ol>
    <?php wp_list_comments('type=pings&callback=list_pings'); ?>

    Lastly, you’ll need to add the following code to your functions.php file (which can be created if you don’t already have one):

    <?php
    function list_pings($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    ?>
    <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?>
    <?php } ?>

    That should clean up the trackbacks/pingbacks section and you can also apply the same changes if you use a plugin to display tweetbacks.

    The other thing you may want to do is fix the comment count to only show actual comments, filtering out the trackbacks/pingbacks which are included in your comment count by default.   Simply add the following code to your functions.php file (which again can be created if you don’t already have one):

    <?php
    add_filter('get_comments_number', 'comment_count', 0);
    function comment_count( $count ) {
    if ( ! is_admin() ) {
    global $id;
    $comments_by_type = &separate_comments(get_comments('status=approve&post_id=' . $id));
    return count($comments_by_type['comment']);
    } else {
    return $count;
    }
    }
    ?>

    So there you go.  Anyone have any other tips for cleaning up your comment form?

  • Leave a Comment
  • How To: Hack WordPress Theme Template Pages

    The key to being able to display exactly what you want in WordPress is understanding WordPress theme template pages. These are the theme files that display pages, not the ones that perform functions like comments, sidebar, etc. Most of us don’t use the WordPress default theme that comes with installation, and end up downloading a free theme from the Internet. This is a great way to customize your blog, but not all theme authors code their theme the same way. The capabilities of that theme largely depend on how much time the web designer took to code it, in addition to their knowledge of WordPress itself.

    I’m going to explain everything you need to know to be able to customize all your theme pages any way you want, and this will give you enough information to begin coding your own theme as well. Even if you’re an ‘expert’ theme coder, you should learn something new from this article.

    How WordPress Works

    The most important thing you could learn about WordPress is the Template Hierarchy, or – “the order in which WordPress calls pages”. The ONLY file that is required in the PHP files of any WordPress theme is the “index.php”. That’s it! That one file could handle every single function WordPress performs (if you wanted it to). Or, you could have a WordPress theme that had a PHP theme for for every single WP function (or anything in between).

    The Order of Things

    Every time a WordPress page is called the WP ‘engine’, if you will, determines (through process of elimination) what kind of page it is. It’s kind of like a “where am I?” function. WordPress says “what page am I…” and in turn tries to call pages in a specific order. If WP doesn’t find the PHP file it needs it just defaults to the “index.php” file and uses it instead. There are 9 basic kinds of pages WordPress looks for first:

    Am I the Home Page?
    If WP thinks it’s on the home page it will look for “home.php” first, and “index.php” second.

    Am I Post Page?
    (Single) post pages look for “single.php” first, and then default to “index.php”.

    Am I a ‘Paged’ Page?
    (Static) or ‘paged’ pages in WordPress look for a “pagetemplate.php” first (if assigned when published), “page.php” second, and default to “index.php” last.

    Am I a Category Page?
    When WordPress determines it’s on a category page first it looks like a category specific ID page, such as “category-7.php”. If it doesn’t find that it next looks for a “category.php” (which would be used on every category page). If that’s not there is searches for “archive.php”, and last it defaults to “index.php”.

    Am I a Tag Page?
    If WordPress is on a tag page it tries to load “tag-slug.php” first, with ‘slug’ being the name of your tag. If your tag is ‘wordpress hacks’ the tag slug page would be “tag-wordpress-hacks.php”. It that’s not available, WP next looks for “tag.php” which would load for all tag pages, then “archive.php”, and if that’s not there last it defaults to “index.php”.

    Am I an Author Page?
    If your blog has multiple authors, first it looks for “author.php” to display the details. If that’s not there, it tries to load “archive.php”, and last it defaults to “index.php”.

    Am I an Archive Page?
    Archive pages are loaded when WordPress loads a date based page for previous posts. First it tries to load “date.php”, then “archive.php”, and last it defaults to “index.php”.

    Am I a Search or 404 Page?
    If WP determines it’s on a search (results) or 404 (not found) page the it tries to load either search.php or 404.php. If not, the default is once again “index.php”.

    Am I an Attachment?
    Out of all the WordPress theme template pages, the attachment page is probably the one used least, and I have to admit – I’ve not seen a single one of these in any of the hundreds of themes I’ve downloaded. WordPress uses these special pages usually for uploaded content, which would explain why it first looks for “image.php”, “audio.php”, “video.php”, or “application.php”. Then it tries to find “attachment.php” or “single.php”, and if none of those are available it also defaults to “index.php”.

    Inner Workings of WP Theme Templates

    As I said before, you could use a single index.php file to handle the 9 types of pages. You would simply code in some conditional tags, like I showed you in the last tutorial I wrote here on WP Hacks. A single index.php would then just contain code to say if is_home, do this, if is_single do that, etc. That’s a lot of code for just one page, and a bit unorganized – and it doesn’t leave a lot of room for customization.

    Coincidentally, like WordPress searches for 9 basic pages – each theme template page also contains 9 basic WordPress elements:

    1. a header call
    2. opening of ‘the loop’
    3. a call to get the permalink and (some) meta
    4. a call telling WordPress what to get
    5. a call to get either the content or an excerpt
    6. (maybe) more meta
    7. closing of ‘the loop’
    8. a sidebar call
    9. a footer call

    Those are only the WordPress elements, of course the PHP code to make them work is usually scattered throughout the appropriate HTML code make your theme’s layout and graphic design work properly. I’m going to explain these elements a bit more so you can understand how you can customize (or create) nearly any theme template page.

    Header, Sidebar, and Footer calls

    I’m going to handle all 3 of these elements at once, since they are all basically the same. When you see this code in a template:

    <?php get_header(); ?>

    WordPress is simply opening the “header.php” file. The same is true for get_sidebar (sidebar.php) and get_footer (footer.php). You could have multiple headers, footers, or sidebars, see the earlier link above for conditional tags.

    Opening of “the loop”

    The infamous “WordPress Loop” is when a call goes out to the database to do something until WordPress says “stop”, i.e. ‘get me the most recent full text posts in their entirety’. The structure of ‘the loop’ changes depending on what kind of page your displaying, and each of the 9 basic types of pages WordPress tries to load has a ‘loop’.

    The opening of the loop generally looks like this:

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

    You may see it broken down with have_posts on one line to define conditional tags with the while and the_post on another, but it’s still the opening of the loop, and it’s pretty much the same in all pages. One way to use the multi-line loop opending is to place a parameter between “if have_posts” and the rest by using query_posts in between to show only a single post, posts from a time period, the last post only, posts from certain categories, or even change the ordering of posts being iterated in the loop.

    A Call to Get the Permalink and (some) meta
    The very last section of the loop opening (the_post) actually makes individual data available through each iteration of the loop. This data referred to usually as “post meta” because it’s descriptors and identifiers for the individual content being looped through. Typically things like the permalink (URL), title, date, etc. I say ‘some’ meta, because most themes show some things before the individual post content, and then some after – such as categories and tags.

    Here’s a short list of things you can call in post meta: the_permalink, the_ID, the_title, the_time, the_author, the_author_email, the_author_posts_link, the_category, single_cat_title, the_tags, single_tag_titls, edit_post_link, comments_popup_link, comments_rss_link

    Example code you might see for post meta would be something like this:

    <div class="post" id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    </div>

    A Call Telling WP What to Get
    Next WordPress will decide how much of the actual individual post content to get for you. How much is gathered from the database depends on whether your look uses “the_content” (to get it all) or “the_excerpt” (to get part of it).

    (Maybe) more meta
    As I previously mentioned, the common things to see after a post are assigned categories or tags, and sometimes you see an “edit” link here as well. Some themes even put date published meta after the post content.

    Closing of ‘the loop’

    The code looks like this:

    <?php else : ?>
    <?php endif; ?>

    Typically it’s on more than one line in case you want to build an option in, such as a message “Sorry, we didn’t find anything”. After the sidebar, before the sidebar and footer calls, is where you typically find the “next” and “previous” navigation links.

    Bastardized Loops?

    Well, just because most loops look like the examples I just gave you, doesn’t mean you can’t bastardize them in just about any way you can imagine. I recommend you read the WP Codex page The Loop in Action for examples of archive, category, and single post formats – as well as static home page.

    The Codex official page for the loop has several examples of how to place multiple loops in one page.

    Conclusion

    Armed with just a tiny bit of knowledge, you can hack just about any WordPress theme template page to do just about whatever you want! Now that you understand (in great detail) how WordPress calls it’s pages and how the loop works, you can conquer any task! Have fun customizing your blog’s theme!

  • Leave a Comment
  • How To: Use WordPress Conditional Tags to Hack Your Theme

    By using simple conditional tags – it’s pretty easy to add some very basic hacks to your WordPress theme to have more control over what’s displayed when.

    Here are some things you could do with a conditional tags:

    • Display something only on certain pages
    • Display something only on certain categories
    • Display something in header and footer only at certain times
    • Display something only on sub-children of particular pages
    • Display something only in the WP dashboard
    • Display something in the sidebar only when certain conditions are met
    • Do something only when there’s a “sticky” post
    • Do something only when a “page template” is used
    • Do something only for “author pages”
    • Display something only on search or 404 pages

    Let’s say you want something to display only on the homepage, or just category pages, or maybe just your 404 (not found) page – it’s quite easy to do. You don’t have to be a hardcore programmer (I’m not for sure) to implement these very simple theme hacks.

    Where to Use Conditional Tags

    It all depends on your your theme is structured. I’ve seen WordPress themes that a single “index.php” file handle just about everything, and other ones that use only the home.php, index.php, single.php, archive.php, and category.php files. You could handle everything with a bunch of code in one file if you want using conditional tags, have individual files for each thing, or any combination in between.

    Most themes I’ve encountered usually have an index.php and a single.php only. If you want to know what pages WordPress looks for first in a theme before defaulting to the “index.php”, read the official WordPress Template Hierarchy page.

    Conditional tags are great because you can use them both in and out of the loop. You can use them directly in theme pages, but you could also use them in your header, footer, comments, and sidebar files. Actually the sky is the limit, and you have only your own imagination to limit you!

    Conditional Tag Examples

    The worst thing I see on most posts about conditional tags is that they don’t have a lot of examples for you to draw from – so I’ll try to give you a few ideas to get you started…

    If This is XYZ page

    One of the most common ways to use a conditional tag is to add a filter of sorts to tell WordPress “if I’m on ‘XYZ’ WP page – then do this. The most common reason would be maybe to show certain things (ads, text, messages, graphics, scripts, flash) in certain places.

    For example, let’s say you want to display a message to visitors on your home page only…

    <?php if (is_home()) { ?>

    Welcome, you will only see this message on my homepage!

    <?php } ?>

    replace “is_home” with “is_front_page”, “is_single”, “is_sticky”, “is_page”, “is_page_template”, “is_category”, “is_tag”, “is_author”, “is_date”, “is_archive”, or “is_attachment” to make your message show up on nearly any WordPress page. Remember, once the condition is met, you can “do” anything – from including a file to showing special graphics, running a script, anything! You could use this condition for example to show an ad on just your homepage, or just single pages.

    If this is XYZ page show this, else show that

    The nice thing about conditional tags is the fact that you can have as many conditions as you want…like this:


    <?php if (is_home()) { ?>

    <p>Show this!</p>

    <?php } elseif (is_single()) { ?>

    <p>Show this instead!</p>

    <?php } elseif (is_category()) { ?>

    <p>Show something different!</p>

    <?php else { ?>

    <p>Show this if no conditions are met</p>

    <?php } ?>

    OR – you could even structure it in such a way that you lump some conditions together like this:

    <?php if (is home() || is_single() || is_category() || is_page()
    || is_archive() { ?>

    <p>Show this on all those pages!</p>

    <?php } ?>

    The double-pipe or || in the code signifies “OR”, so WordPress knows, if this is home, or a single page, or a category page, or a “page” page, or an archive page – then so something.

    Show Everywhere, Except…

    Sometimes you want to show something everywhere possible except just one or two places…

    <?php if (is_home()) {
    }
    else { ?>

    <p>Show this everywhere!</p>

    <?php } ?>

    With this code we just say if it’s “home” do nothing, else show do this. You could add multiple conditions (exclusions) to this using the || OR operator as in previous examples.

    Getting even more specific

    One thing I hadn’t mentioned was that you could pass additional parameters to the conditional tags for even finer grained control. For example, instead of targeting are single post pages with “is_single”, you could actually target just one using any of these formats:

    is_single(’25’) // uses posts ID
    is_single(‘Title of my post’) //uses the exact title of the post
    is_single(‘title-of-my-post’) //uses the permalink of the post
    is_single(array(25,’this title’,’this permalink’)) //uses when any of the 3 are true

    You can use similar parameters for paged pages, template pages, categories, tags, etc. The official WordPress Conditional Tag page in the Codex lists them all.

    Force WordPress Functions for Certain Conditions

    Have you ever not wanted to add people to your blogroll because their link will display on EVERY SINGLE page of your WP powered site? That’s an easy hack with conditional tags, because you could hack your sidebar to display your blogroll ONLY on your homepage like this:

    <? php if (is_home()) {
    wp_list_bookmarks();
    }
    ?>

    You could modify this to display just about anything in the sidebar for whatever conditions you want. Let’s take this a bit further though – let’s say that maybe I want a special header or footer when certain conditions are met? You can do that too…

    <? php if (is_home() || is_single() || is_page()) {
    get_header();
    }
    elseif (is_category() || is_tag()) {
    include (TEMPLATEPATH . '/header2.php');
    }
    elseif (is_404() || is_search())
    include (TEMPLATEPATH . '/header3.php');
    } ?>

    Using that example code you could have as many different headers, footers, or sidebars as you wanted and you could include them for whatever conditions you specified. Just replace get_header with get_footer or get_sidebar, and edit the rest include the files you want.

    Using Conditional Tags to Change Styles

    So far my conditional tag examples have been to show you how code conditions to do this or include that. Another very simple (and powerful) was to use conditional tags is to just use them for coding style. You could have any element (paragraph, div, heading) change colors or font size or anything related to style when certain conditions are met.

    Let’s take a very simple example, maybe your pages have content contained within one div like this:

    <div id="content" class="main">
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    </div>

    In most themes, that main “div” is styled the same way on EVERY single page of the theme. Maybe you want it styled one way for your homepage, but another for paged pages, single posts, archives, etc. What you do in this case is to write different classes in your stylesheet for each and call them something like “single”, “archive”, and “paged” – and then you code it like this:

    <div id="content" <?php if (is_home()) { ?> class="home"
    <?php } elseif (is_page()) { ?> class="paged"
    <?php } elseif (is_single()) ?> class="single"
    <?php } elsif (is_archive()) { ?> class="archive" <?php } ?> >
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php endwhile; ?>
    </div>

    You use any variation of this to control any element of your theme at will under nearly any condition. This would also be a great way to control your Post title and meta and have it display different things on different parts of your WordPress powered site.

    Conclusion

    I think mostly that the power of conditional tags is widely underutilized. Many of us just take for granted the way a theme works and looks, and forget that with just a few strokes of code and some imagination – we can change just about anything under the sun in our WordPress theme! I’d like to see some comments on what kinds of things you’ve used conditional tags for in your WordPress site (code samples welcomed!).

  • Leave a Comment
  • How To: Update Your WordPress Database Name

    Last week while I was doing some spring cleaning, I decided to move a few of my sites over to a new CPanel.   The move went fairly smoothly, but once everything was moved, there was the matter of updating the WordPress database to show the new database name. If you are wanting to do something similar, here is what you need to do.

    All you need to do is update the wp-config.php file to point towards the new database name, which should be found in the root of your WordPress installation.   Open the wp-config.php file and look for the following code:

    define('DB_NAME', 'dbname');

    Where it says dbname, update the name of your database.  If your login name changed, you’ll want to update that as well.

    Once that was done, the only problem I encountered was that I was unable to upload pictures.   The fix?  Go into your WordPress dashboard and go to Settings –> Miscellaneous and update the path where images are uploaded to.

  • Leave a Comment
  • Make an Apple.com Style Breadcrumb for Your WordPress Blog

    Breadcrumbs, as has been said before on WPHacks, are very useful, both for your SEO and reader’s navigation. In other words, there is no reason why you shouldn’t have them on your site.

    There are a number of breadcrumb plugins you could use, but with a bit of WordPress code, you can avoid this. If you use sub-categories, then this will only display the name of the sub category.

    A typical breadcrumb is something like this:

    Home >> [Category] >> [Post Title]

    WordPress can very easily do this – to get the name of the category the post is in, all you need is

    <?php the_category(); ?>

    Then, to display the post title, the code you need is

    <?php the_title(); ?>

    So our final code, with some arrows added in is:

    <a href="/">Home</a> &raquo;  <?php the_category('   '); ?>   &raquo; <?php the_title(); ?>

    So now that you’ve got your breadcrumb sorted, you can take this one step further and spice it up a bit. For the next part, we’re going to be using the code from a tutorial at Janko at Warp Speed, and with this code, we’re going to turn our breadcrumb into something that looks like the ones you see on Apple.com!

    First, download the html version here, and open it in a your web editor (ie Notepad, Dreamweaver etc). Scroll down until you find <ul id=”breadcrumb”>. This is where we’re going to start editing. All you need to do is copy and paste the following code:

    <ul id="breadcrumb">
    <li><a href="/" title="Home"><img src="/images/home.png" alt="Home" class="home" /></a></li>
    <li><?php the_category(', ') ?></li>
    <li><?php the_title(); ?></li>
    </ul>

    This is basically the same code as we had above, just putting into a list. Make sure you upload the home.png file to /images/, and while you’re at it, upload the other images.

    Next thing we need to do is the CSS. Go into your style.css and paste the following:

    #breadcrumb {
    font: 11px Arial, Helvetica, sans-serif;
    height:30px;
    line-height:30px;
    color:#9b9b9b;
    border:solid 1px #cacaca;
    width:100%;
    overflow:hidden;
    margin:0px;
    padding:0px;
    }
    #breadcrumb li {
    list-style-type:none;
    float:left;
    padding-left:10px;
    }
    #breadcrumb a {
    height:30px;
    display:block;
    background-image:url('/images/bc_separator.png');
    background-repeat:no-repeat;
    background-position:right;
    padding-right: 15px;
    text-decoration: none;
    color:#000;
    }
    .home {
    border:none;
    margin: 8px 0px;
    }
    #breadcrumb a:hover {
    color:#35acc5;
    }

    Once you’ve done that, then you’re done! If you copy the code from the source file (which you should), then make sure you change the url of the images.

  • Leave a Comment
  • How To: Display WordPress Categories without Children

    About a week ago I decided I was unhappy with the archives plugin I was using to display our archives, so I decided to build a custom archives page.   This archives page is fairly basic in that it displays the categories and archives side-by-side, then all the posts below it.   This way people can use Ctrl+F to quickly find posts they are looking for. 

    After getting the page built, I realized all of the “child” categories I use for the WordPress Hacks theme was causing some problems, so I decided to remove them from the display.   After all, these posts can also be found in their parent category. 

    If you are displaying your categories somewhere and would like to remove the children, here is the code you’ll need (for WordPress 2.5+):

    <?php wp_list_categories('title_li=&depth=1&show_count=1') ?>

    The depth=1 is the important one for the purpose of this hack as it is what tells WordPress not to display more than your parent categories.   By default, it is of course set to depth=0 (shows all categories).   If you are wondering what other options you have, here is what the WordPress Codex lists for the depth parameter:

    • 0 – All Categories and child Categories (Default).
    • -1 – All Categories displayed in flat (no indent) form (overrides hierarchical).
    • 1 – Show only top level Categories.
    • n – Value of n (some number) specifies the depth (or level) to descend in displaying Categories.
  • Leave a Comment
  • How To: Do a Trademark Search

    Last month when we switched from HackWordPress.com to WPHacks.com, I mentioned that one part of the move was due to the trademark violation in the old domain name (WordPress is a trademarked term).

    Looking back, I really wish I would have known about the trademark prior to launching the blog. Moving your blog to a new domain name can be a huge hassle (I explained what was involved here) and your blog will usually take a huge hit in the search engine rankings (either temporarily or permanently). This is because most of those backlinks accrued over the past year are pointing towards the old domain name, etc.

    Being someone who manages quite a large sized domain portfolio (300+ domains), I’ve spent a lot of time over the past year or so learning how to do a trademark search when researching what domains to invest my money in and which domains I want to develop into web properties. There seems to be a good amount of interest from others wanting to know how to do this, so hopefully this post will fill that need.

    Why Should I Worry About Trademark Violations?

    Before I explain how to do a trademark search, I wanted to quickly discuss why avoiding trademark violations is so important. A trademark is filed by a company to protect their brand.

    How many of you call tissues “Kleenex”? Kleenex describes one brand of tissues, but because they did not protect their trademark, the term Kleenex has instead become a generic term for tissues.  This of course caused them to lose any control they might have had over how their name is used.

    Like any good company would, Automattic wants to protect the term “WordPress” from becoming a generic term. This is why they do not allow others to use the term “WordPress” in their domain name. This can lead to confusion with readers who believe that the domain is an official WordPress site or affiliated in some way with WordPress, which could eventually lead to problems for WordPress users (if the content is bad, incorrect, or the site is malicious in some way).

    Because of this, most trademark holders will go a long way to protect their brand, including filing lawsuits.   Lawsuits, or threatening lawsuits, has become very common with people registering names like FacebookApplications.com, DiggThis.com, etc. In order to avoid complications, avoid being forced to pull down a website/blog, or having to move your site to a new domain, you’ll want to first make sure that your potential domain/website is free of any trademarks.

    Note:  If you register a domain prior to a trademark being filed by a company, that company usually won’t have rights to take the domain from you UNLESS you are displaying ads on the site or somehow making money off their brand.  Keep this in mind if you own a domain and an upstart grows popular fast.

    How To Do a Trademark Search

    Okay, so now you know why doing a trademark search is so important.   Here are the 5 steps you need to follow to do a trademark search:

    1. Visit the US government’s sitesearch page.
    2. Click Search at the top of the right sidebar menu.
    3. Click New User Form Search (Basic).
    4. In the Search Term field, you’ll want to enter the keyword you want to check on the trademark of.
    5. Click Submit Query.

    When doing your search, you’ll want to make sure to search for your term with and without spaces. An example would be if you were looking for Burger King, you would try both “burgerking” and “burger king”.

    If you follow the above steps and search for the term “wordpress” you’ll see that it is indeed trademarked, but you can use this method to search for just any keyword you want to. I recommend doing this prior to ever launching a website of any kind, just to make sure. I also used this process after picking my business name to ensure that I wouldn’t run the risk of losing my business identity at some point down the road.

    Are you always doing a trademark search prior to launching a new website or blog?

  • Leave a Comment
  • How To: Move Your WordPress Blog to a New Domain

    Last Friday I announced that our site has moved from Hack WordPress.com to where we are now, at WPHacks.com. Towards the end of the post we got a lot of positive feedback from people wanting to know what all was involved with the process, so I’ve decided to attempt to document it here.

    Here are the initial steps you’ll want to take when moving to a new domain name.

    Existing Domain:

    • Export Your WordPress Posts – You can find the Export option under the Manage tab in your WordPress dashboard. You’ll want to save the file somewhere on your hard drive where you can find it a little later.
    • Download Your wp-content Folder – This step requires FTP access.  You’ll want to copy over your wp-content folder on to your hard drive or place it somewhere you can find it later so that you can upload it to your new domain. This should grab all of your existing plugins, themes, uploads (pictures), etc.   You’ll also want to download your favicon and Robots.txt file (if you have either).
    • Sub Domains and Sub Directories – This won’t apply to everyone, but if you’ve set up any sub domains or sub directories for your blog, you’ll want to grab the same files from them as well.

    New Domain:

    • Install WordPress on the New Domain – This can be done manually or via Fantastico if you have CPanel.
    • Upload Your wp-content Folder – This requires FTP access to complete.  Just override the existing wp-content folder from your fresh WordPress install.
    • Import All WordPress Posts – You can find the Import option under the Manage tab in your WordPress dashboard.  When it asks for the import file, use the one that was exported and saved on your hard drive earlier.
    • Activate Your Theme & Plugins – Head into the Design and Plugins tabs and make sure you have the same theme and same plugins activated as the old domain name.
    • Update Your Settings to Match the Old Domain – Update all of your settings to match the old domain, including all of your plugin settings you just activated.
    • Inspect Your Theme – View your theme with your plugins activated and settings in place to ensure that everything looks like it matches the old site on the new domain.  Test some of the functionality as well to ensure everything is working properly.
    • Upload and Run the Update URL’s Plugin – The Update URL’s WordPress plugin is brand new (just came out this month) WordPress plugin and the timing couldn’t have been more perfect for me!  Once activated, simply enter your old domain URL and the new one.  It will go through all of your old posts and update the domain part of the URL with the new one, and it only takes a matter of seconds.  Note:  I won’t update anchor text, only the domain in the URL.
    • Repeat Steps for Sub Domains and Sub Directories – Upload and setup your sub domains and sub directories using the same steps above.

    Domain Move Troubleshooting:

    • For some reason, since WordPress 2.5, the export/import feature of WordPress works great but sometimes causes problems with an unresponsive script error whenever you access the Write panel. I will be publishing a post tomorrow that explains how to fix this error, so make sure you are subscribed to our feed.

    Once the move is completed and everything seems to be working well, here is a mini checklist of extra things to do before making the move official:

    • Update Your Feedburner Feed – You need to edit your feed details in your Feedburner account with the new domain’s source feed
    • Update Your Email Address – This one is optional.  Setup an email account on your new domain name (for example, I setup Kyle AT WPHacks DOT com for the new site).  I recommend using Google Apps which makes it really easy and lets you take advantage of the Gmail spam guards that Google has in place (plus all of the other Gmail features).
    • Update Your Gravatar – This one is optional as well.  Log in to your Gravatar account and add the new email address you just setup.
    • Update Your PPC Campaigns – If you purchase PPC advertising with AdWords, Yahoo, or whoever, you’ll want to update the destination URLs.

    Once you’re done, all that is left is to go to your domain registrar and forward the old domain to the new domain (also known as a 301 redirect). Depending on your registrar, this is usually really easy and self-explanatory.  I would also wait 6-12 hours to make an announcement on the new domain name so that the DNS can resolve at the new domain name (it can sometimes take up to 48 hours). Depending on your web hosting, you may also be able to do the forward there to avoid this problem.

    Doing this will cause all links to your old domain name to be redirected to the equivalent URL on the new domain name (assuming you use the same URL structure on the new site). It will also let Google and the other search engines know you have moved. Usually within a week, depending on the search engine, they will have gone through and updated their index with the new domain URL’s.

    This of course means that you shouldn’t use any human traffic, but you will take a hit when it comes to your search engine rankings. This is because the links are pointed towards the old domain name, so when Google determines your rankings, they will see the new URL has zero backlinks. This is why it is beneficial if you can get people to update the links in their sidebars or posts to the new domain URL.

    Any questions?  Need clarification on anything?  Please let me know in the comments below!

  • Leave a Comment
  • How to: Create a Multi-Language Blog

    Using WordPress plugins to automatically translate blog content
    This is the easiest solution. A few WordPress plugins allows you to put some clickable flags in your sidebar, that will automatically translate your content to another language using, for example, Google Translate.
    This is a great solution if you’re looking for a way to make your content available for people that doesn’t speak your language, but you guessed it, the automatic translation isn’t as good as a human translated text.

    Anyways, if you’re interested in theses plugins, here’s a small list. I didn’t tried them all myself, though.

    Using categories and a few hacks

    If you’re a perfectionist, you probably don’t really like the automatic translations provided by Google. In my opinion, if it’s okay for a personal blog, but automatic translations should be avoided on a professional blog.

    For this hack, we will use categories. Go to your dashboard and create categories/sub-categories following the example below:

    English
        One category
        Two categories
    Français
        Une catégorie
        Deux catégories
    Deutsch
        Eine kategorie
        Zwei kategorien

    Of course this is just an example, you can add as many categories as you want. The thing to remember here is that we’re using top level categories for languages, each of them having sub-categories organized by topics.

    Now, you should post at least one example post in each sub-category. Once you’re done, we can start editing our header.php template.

    The idea is quite simple: First, we must display the available languages, and then, a menu with the sub-category related to the current language. We must also think about defining a default language, which will be English in this example.

    1 – Creating the language menu
    Insert the following code where you want the language selection menu to appear:

    <?php
    wp_list_categories('title_li=');
    $lang = 1; // Sets the default language
    ?>

    As you can see, we just need the good old wp_list_categories() function to get our available languages.
    Then, we have to keep a php variable containing the id of the top level category, in order to display the navigation menu in the selected language. We must give a default value to the $lang variable. This default value will be the category id of the language you want to set as default.

    I noticed that many people should have trouble to find the ID of a particular category. If you do, you should definitely read this post.

    2 – Navigation menu
    Now, we got a php variable containing the id of the mother category. As the top-level categories are languages, we know which language the user is using.

    We simply have to display second-level categories.

    <ul>
    <?php
    wp_list_categories('title_li=&child_of=$lang');
    ?>
    </ul>

    3 – Retrieving category
    Here’s a sample code you can use to automatically list posts from a category. This code get the current category (in this example, the language) and then displays the related posts.

    <?php foreach((get_the_category()) as $category) {
          	$thecat = $category->cat_ID . ' ';
        	query_posts('child_of='.$thecat);
    	if (have_posts()) : while (have_posts()) : the_post();
    	   //Classic WP loop
    	endwhile;endif;
    ?>
  • Leave a Comment