Country Living

You just never know what I’ll be up to around here. I could be quilting one day and building a barn the next. I just love living on our 10 acres with our heapin’ mess of critters.

Down Home Cooking

Cooking is really the first social networking activity humans ever learned. I love simple, good tasting, home cooked food (if it’s healthy that’s a perk!). Pull up a stool to the counter and sip some coffee while we whip up some supper together.

Family Life

Family is what life is all about. No one is going to leave this earth and wish they had spent more time at work. Some simple things to enhance your family life. “Try it, you’ll like it.”

The Moxie Mom

One of the joys of my life is getting to be a stay-at-home mom. I am so blessed to have a husband who supports me in this endeavor of raising our children. We have fun with homeschooling, 4-H, church, our farm/ranch/zoo and love living in Texas.

WordPress

My favorite blogging platform is WordPress.org. There are just so many possibilities. Want some “how-to” in layman’s terms? See some of my favorite tips, tweaks, plugins and themes that WordPress has to offer while avoiding some pitfalls.

Home » Headline, WordPress

Create a WordPress Navigation Link to External URL

Submitted by Wendy Merritt on Friday, 16 January 200925 Comments

halo wordpress Create a WordPress Navigation Link to External URLThat is a wordy title! I had a terrible time figuring out a way to create a link to an external website. I found many websites with a lot of coding jargon. Here is a way to do it that is very simple. It took me about 2 minutes and it worked like a charm.

You are going to add a page to your WordPress blog BUT that page will only be a link to the outside URL of your choosing. It will magically be added to your header navigation and need no lengthy coding.

Most WordPress themes use page-based navigation menus, but unfortunately this doesn’t allow for you to insert custom links wherever you want them. So nothing’s perfect.

Let’s create a simple page template that will allow you to turn any page into a link that leads to whatever external URL you want it to go to. Make sure you don’t leave any white-space, save the code below as “redirect.php” and upload it to your theme’s folder (you should see another file called “single.php” and “page.php” in this same folder…among other things).

<?php
/*
Template Name: Redirect
*/

if (have_posts()) {
the_post();
$pattern = ‘@(https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?)@’;
preg_match($pattern, get_the_excerpt(), $matches);
if ($matches[0]) header(’Location: ‘.$matches[0]);
else echo ‘Enter a URL into your page body text.’;
}
?>

Go ahead and create a new page to take this new template for a spin. When you enter the title for the page it will be the title for your links navigation…same as always. Take a look at the “Attributes” and see there is now a Template called “Redirect.” There should be nothing on your page but the link to your chosen navigation menu: “http://www.smashingonlinesurveys.com” (whatever your URL is).

You’re done! Now that didn’t hurt did it?

Using WordPress’ built in page ordering function you can now position that external-page-link anywhere you want it in your navigation menu.

If you look on any WordPress support forum you will see this external page link issue is a common one. There are many ways, maybe a couple of plugins that can handle this common complaint but this is an easy fix using this .php file.

There are other better ways to build your menus, but if you’re like me you love your theme and all you want is to add an extra link or two.

See, I told you it was easy :-)

Like this blog post? buy me a coffee or send me a tip!



The Moxie Mom Blog!
If I can do it! You can do it too! Celebrating Texas country living, down home cooking, family life, figuring stuff out and being a stay-at-home moxie mom computer geek.

followmeontwitter Create a WordPress Navigation Link to External URL Blessings,
Wendy Merritt
The Moxie Mom

XXO (A kiss on each cheek and a hug)

If you enjoyed this article get updates via my RSS feed.The Moxie Mom Blog RSS feed

Popularity: 32% [?]

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • LinkedIn
  • Live
  • MySpace
  • Ping.fm
  • Reddit
  • StumbleUpon
  • Technorati
  • Twitter
  • Yahoo! Buzz
  • Print

Related Posts



1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...



25 Comments »

What are your thoughts?

You must be logged in to post a comment.