Page Links To

About

Page Links To is a plugin that allows you to make certain WordPress pages or posts link to a URI of your choosing, instead of their WordPress page or post URI. It also will redirect people who go to the old (or “normal”) URI to the new one, using a redirect style of your choosing (302 Moved Temporarily is standard, but you can enable 301 Moved Permanently redirects i f you wish.)

For instance, say you have a photo gallery installed, but can’t be bothered to integrate it into WordPress. You’ll still probably want to have a link to it from your WordPress blog. With this plugin you can create a new page called “Photos,” and give it a Custom Field links_to with the value being the URI to your photo gallery. “Photos” will show up when you use wp_list_pages();, but instead of linking to the (blank) “Photos” page, it will link you your photo gallery!

Another usage scenario is that you have content that was on a post, and want to move it to a page. You could redirect the post to the new page. And if you use a 301 redirect, search engines will eventually “find” the new location and change their links.

This plugin uses only two simple MySQL queries, no matter how many total pages or links_to enabled pages you have, so you don’t have to worry about scalability.

Usage

To redirect a page or a post, scroll down to the “Custom Fields” section on the edit screen for that entry and enter in a key of links_to with the value being the full URI you want to redirect to. If you want this to be a permanent move, you can additionally add a meta key of links_to_type with a value of “301″ (without the quotes). After saving the entry, the redirect will be active!

New in version 1.3: Now you can create a links_to_target meta key, and provide the target you would like for the link (like _new, to open the link in a new window). The target you choose will be used in wp_list_pages().

Download

Instructions

  1. Upgrade to WordPress 1.5.1.3 or higher (WordPress 2.0 required for tab highlighting feature)
  2. Upload page-links-to.php to your /wp-content/plugins/ directory
  3. Activate the “Page Links To” plugin in your WordPress administration interface
  4. Create (or edit) a page to have a title of your choosing, and a parent page of your choosing (leave the content blank)
  5. Down below, add a meta key of “links_to” (without the quotes) and give a full URI as its value

That’s it! Now, that page will link to the “links_to” URI instead of its WordPress page URI.

Possible Uses

  • Linking to an on-site non-WordPress resource (e.g. photo gallery)
  • Linking to an off-site resource (e.g. Flickr or del.icio.us page)
  • Placing a link to a 2nd, 3rd, or nth level page on the top level (i.e. you might have /archives/tags/, but want “tags” to show up on the top level)
  • Adding a link to your blog’s front page without having to modify your template and hack it in manually

Leave any bug reports or feature suggestions here in the comments.

Versions

  • 1.4 Fixes to tab highlighting
  • 1.3 You can now specify a link target via links_to_target, tab highlighting moved to WordPress 2.0 style
  • 1.2 If you link to an internal WordPress page, like a category, the menu item will get the current_item CSS class when you’re on that page
  • 1.1 Posts can have redirects, can specify redirect type (301/302), get_permalink() is filtered for posts.
  • 1.0 Initial public release.

I’ve spent a lot of time writing this code and supporting it. If you derive some benefit from this code, please consider showing your gratitute in a more tangible
way. Thanks!

I have received $0 this month for my coding efforts.

Donate with PayPalAmazon.com Wishlist


511 Responses to “Page Links To”

Comment pages: « 1 2 [3] 4 5 6 »

  1. Rob |

    Any idea why your plugin interferes with the KG Archives plugin? I’m getting this error on my archives page:

    Warning: Missing argument 2 for txfx_filter_links_to_pages() in /home/electro/public_html/wp-content/plugins/page-links-to.php on line 90

  2. Mark (post author) |

    Rob,

    I don’t see that error there… don’t know why you’d be getting that.

    A couple of observations:

    • Line 17 of the KG Archives plugin isn’t going to work, because $archive_page_slug isn’t declared global within the function.
    • You should upgrade to WordPress 2.0.4 for security reasons
  3. Rob |

    Thanks, Mark for taking the time to comment. Shoot for some reason the archives tag got eaten. If you check again, those errors are showing again.

    Hmm, I’ll have to look at that line 17. Interesting!

    And I’m waiting for my service provider to update their Fantastico to WP 2.0.4.

  4. kathy |

    Hi Mark,

    This plugin is just what I was looking for. The only problem I’ve had with it is the tab highlighting. I looked at the comments above and I’m not quite sure what you mean by manually removing part of the code in header.php. Could you be more specific?

    Also, have you found a way to keep the tab highlighted when you click on say a photo within the photo gallery?

    Thank you so much!

  5. Stephan Brenner |

    Thanks for that nice plugin.

    According the tab highlighting that should be fixed in 1.4 I found a bug. In line 147 at one place you must use $this_url instead of $page:

    trailingslashit(get_bloginfo(’home’))) == str_replace(’http://www.’, ‘http://’, trailingslashit($this_url)) ) )

    With that it works.

  6. garnet |

    Hey, I don’t understand what “add a meta key of “links_to” and give a full URI as its value” would look like. If I want to link to http://glitteringstew.com/reed

    should I do

    how does this work?

    thanks for any help.
    David

  7. Mark (post author) |

    David,

    On the post screen, scroll down to the “Custom Fields” section.

    Consult this image. Hopefully that should clear it up.

  8. garnet |

    Got it, Mark. Way at the bottom of the page. Never saw that before. OK, I got it to link to the page, now I’d like to use the links_to_target to a _new page. Do I write links_to_target_new? So far that hasn’t worked. It just goes to the title of the page.

    If it doesn’t work, at least it goes to the new link with just links_to

    thanks,
    David

  9. garnet |

    Mark, I have wp 2.0.4, so tab highlighting (whatever that is) should work.

    Thanks for the neat plugin.

    David

  10. Mark (post author) |

    links_to_target should be entered as a second custom field (after saving the first one). Key is links_to_target, value is _new

  11. garnet |

    Thank you for the help. I appreciate it. I can now link to another blog of mine.

    David

  12. Bonnie |

    This plugin is amazing, and works like a charm. Thanks to this and the Page Category Organiser plugin, I can now have completely dynamic menus on my site, with some of my post categories acting as “pages”. Wonderful. Thank you so much!

  13. Barry |

    Words perfectly for me.

    Thanks you very much.

  14. MauiDan |

    Many thanks! Works like a charm.

  15. Sunil Parmar |

    Thanks a lot.
    Hat’s off to you.:)

  16. Chris |

    This plugin is awesome.

    Thanks so much, I used it to “integrate” Gallery2 with my blog.

  17. Jason |

    Hi. Plugin appears to be working. However, is there a way for the redirected link to be opened within my blog as opposed to opening in a seperate page?

    This would be absolutely perfect

    Thanks in advance,

    Jason

  18. Mark (post author) |

    By default it opens in the same browser window.

  19. Jason |

    Is there any way to change that Mark?

  20. Mark (post author) |

    Set the links_to_target Custom Field to the target of your choice.

  21. Jason |

    Hi Mark,

    I have tried this, but now it is opening the link in a completely new browser window. I want it to open in an existing page that I have created in Wordpress http://mydomain.com/blog/?page_id=5 and keep the menu header (not replace it with new page I have linked to)

    Any ideas?

    Thx

  22. Mark (post author) |

    Jason,

    That’d require a custom template that calls in the relevant code within a WordPress context… that’s a topic beyond the scope of this plugin.

  23. Sammo |

    I made a new page with a link_to /wp-gallery2.php and the menu item link appears. Clicking on the link takes me to the photo gallery as expected. However, the “Blog” tab is highlighted instead of the “Photo Gallery” tab. Any ideas? Thanks

  24. kjk437 |

    Thanks a ton! Exactly what I was looking for, and it works wonders!

  25. Andrew |

    I’m having the same problem as Sammo (#248). I’ve even removed my hard-coded “Home” link and created a page for it. Any ideas? Otherwise, this is an extremely useful plugin!

  26. philglov |

    Very nice, great solution with many applications! Thanks!

  27. Maxime Rousseau |

    Great plugin, works like a charm. Blogged.

  28. James |

    Great plugin.

    However, the tab for the current page does not highlight when I’m in a sub page of the current page - i.e. the gallery - the tab highlights for the top level page of the gallery, but not in any of the sub pages (i.e. the albums) - I am using WPG2 plugin.

    Any ideas?

    Many Thanks,
    James.

  29. Kira |

    The plugin stopped working for me and I don’t know since when because I have not added links using the plugin for a good while. I upgraded to WordPress 2.1 and Page Links To 1.4 a few days ago. Today, when I try to add a link to my forum, I get some weird stuff happening:

    1. I start a new page and give it a title of “Forum” without the quotes, leaving the page content blank;
    2. I add a links_to custom field with a value of “http://www.kalunite.net/forum/” without the quotes;
    3. Click “Publish”;
    The newly created page is not listed among the Pages; instead, it is saved as a post draft by WordPress. Furthermore, the title is “Draft created on January 27, 2007 at 10:51 am” instead of “Forum”. I didn’t dare making changes to that post draft and saving or publishing it because I’m afraid it may mess up my whole blog, so I just deleted it.

  30. Kira |

    I forgot to mention that despite the weird behaviour, my forum _does_ show up in the post preview area when I open the post draft.

  31. Kira |

    Ok, I think I have found a work around to my problem:
    1. Create the page with the desired title and leave the content blank;
    2. Publish it without adding the links_to custom field;
    3. Open the page for editing again and add the links_to custom field; At this point the link to the page disappears from the blog frontpage sidebar;
    4. Go to the admin interface –> Manage –> Pages; The page should be listed;
    5. Click on View;
    The link should now appear on the frontpage sidebar again.

  32. Mark (post author) |

    Kira,

    That’s actually a bug in WordPress 2.1, and not this plugin. The bug is that if you add a custom field on an unsaved Page (and click the add custom field button) and then publish that page, it gets saved as a post, not a page. Thanks for reporting the steps to duplicate it! I’ll look into a fix. For now, you’re right, just save the Page before you add a custom field to it.

  33. Mark (post author) |

    Kira,

    Actually, I may have spoken too soon. :-) Looking into the matter some more… I’ll let you know.

  34. Mark (post author) |

    Kira,

    Okay, WordPress bug, for sure. I triggered it with my plugin turned off. There are many workarounds… typing dummy content and waiting a minute would have fixed it, as autosave appears to repair the problem. You also could have filled in the Custom Field info and hit publish (i.e. not submitted the custom field info before hitting publish… it’ll still be saved). You also could have published the page or even saved it as a draft and then added the custom field.

    I reported the bug and will look into a fix for WP 2.1.1

  35. Mark Barnes |

    Thanks for this plug-in, it’s just what I needed.

    Can I make a feature enhancement suggestion? Could you allow us to put a page id in the link-to box. Then, your plugin could convert that page id to a permalink. It would mean then that if our permalink structure, or page-slugs changed, then internal links would still work.

    I think it would only need a couple of lines of code, and wouldn’t affect current functionality, as you would just need to test whether the input was an integer.

    Thanks for considering it,

    Mark

  36. Paul |

    Hello, just installed this to provide a link to my Flickr Photo Album on Wordpess 2.1.1.

    It works very well indeed, apart from the ‘blog’ tab is always highlighted.

    I’ve been looking around, searching, reading and trying to get this to work without the ‘home’ or ‘blog’ tab, but I’m at the end of my tether so thought I’d ask here for help.

  37. Paul |

    I’m an idiot. Some themes (k2 included) hard code the “blog” link. I just removed the hard coded link and added a new custom “blog” tab/page.

    Thanks again for this little plugin, really useful!

  38. Dave Greenwood |

    Hi, I’m just trying your plug-in and the page linking works great. Thank you. Unfortunately the high-lighting is giving me problems. I am using WP2.12 and k2 theme (but I have tried it with several other themes). I have read previous posts here regarding the hard coding of the ‘home’ page in k2, but even if I remove that, high-lighting does not work correctly. I was looking through your script ( and I speak now as a scripting beginner) and I felt that the ‘class=”current_page_item” ‘ was not getting added to your array when it is first populated, hence the new page list sometimes has 2 or more high lighted tabs, depending on which page I start navigating from, because the original never gets ‘reclassed’. I’m sorry, I just don’t know the coding well enough to investigate this theory further, but I wonder if, even if you can’t fix it, can you say if this might be the case?
    Thanks again for your time to do this plug-in
    Cheers
    Dave

  39. Dave Greenwood |

    Hi again, I’d just like to clarify that I’m using the wordpress header on my non wordpress pages, which I assume is the intended use of this plug-in…

    Cheers
    Dave.

  40. hm2k |

    Where can we see a demo?

  41. hm2k |

    Never mind about the demo, I tried this out on my own setup.

    The only problem was that it breaks the ability to comment on a post.

    It would be great if you have the option for both types of link.

  42. Mosey |

    Such a great idea! One that I really need - so glad that there’s a plugins directory now to show what people *really* use… it seems there are problems with 2.1 as described above? Critically the comments part methinks… have others used it with no problems?

  43. lars |

    hey mark
    thanks for the plugin! ive got a question though. is it fully compatible with wordpress 2.1.2? I cant get it working to link to my flickr account.
    thanks for your attention.

  44. Sonny |

    It is compatible with WP 2.1.2? I make a blank page, add links_to the custom fields key and the URL to the value field, publish the page. When I go back and look for the page, it’s gone. It oddly appears has a draft post instead of a page. I then added a test page, without the links_to customer field, that works as expected. I edited it and added the links_to custom field and save it, but it just shows as a blank page instead of linking as desired. Any ideas?

  45. Jürgen |

    Ok, now i understand the difference between 301 and 302 - Thnaks a lot for this information. Jürgen :-)

  46. Sonny |

    OK, After a bit of fiddling around I think I figured it out.

    1. Add a blank page and save it.
    2. Edit the page and add the meta tag link_to (or another Page Links To meta tag) and the desired destination URL, save the page again.
    3. Now the link works as designed.

    Maybe they’ll get around to fixing it in WordPress one day as it seems to behave just as strangely without this plug-in.

    Thanks for all the work that you put into this plug-in!

  47. Mosey |

    Thanks for the step-by-step instructions, Sonny. :) I am using another plugin called ‘MyComic‘ that also utilises custom fields. The plugin only works if I save the post *first* before I add in the value for the custom fields as well.

  48. Mike |

    I have not yet downloaded the plugin, but I am wondering something…

    Can I use this to track the number of clicks from my Wordpress blog to my external resource?

    Basically, I would like to know if people are clicking the link created by this plugin, or if they are going to the external resource directly (or a different way).

    Thanks.

  49. Mark |

    #292 Comment works for ‘pages’, thanks for the tip. It’s interesting that when directing ‘posts’ to a new URL the plugin works first time, without the need to save first.

  50. nssn |

    I seem to have the same problem as Paul (#278) and Dave Greenwood (#283). I allready read half the internet for a solution but unfortunately the ‘blog’ tab keeps highlighting. Where can I find the lines of ‘code’ that I need to remove?

    It seems like some of you found a solution. Please share your wisdom!

    Thanks!

  51. Paul |

    In the header.php of your problem theme there will be a hardcoded home/blog link. Comment out/delete it. Then I added a page_links_to page for ‘blog’, with the links_to as the full address of my blog homepage.

Comment pages: « 1 2 [3] 4 5 6 »

Leave a Reply