Support » Fixing WordPress » Linking to pages within site

  • Resolved vikkineal



    Just a quick question.

    What is the best way to link to pages within the site without using absolute URLs.

    I’ve hard coded a back button to my articles back and want that to link to my category landing page, but the URL I’ve got is here )on a dev site at the moment)

    Obviously when the site goes live, I don’t want to have to change all the URLs.

    Any suggestions?


Viewing 11 replies - 1 through 11 (of 11 total)
  • Maybe I didn’t understand the question, but you can add this to your functions.php, and use shortcode for URL’s

    // create shortcode for website's home page adress
    function myUrl($atts, $content = null) {
    		"href" => get_option('home')
    	), $atts));
    	return $href;
    add_shortcode("url", "myUrl");

    than, the code in your pages would look like this

    <a href="[url]/rest-of-the-link">something</a>

    or for the uploads folder

    <a href="[url]/wp-content/themes/yourtheme...."></a>

    jack randall


    are you talking about links in post and pages or menus? either way there’s a simple solution for both

    zex2911 – yes i think that’s what i need! Thank you

    jack randall


    when you create a post or page, in the editor you have a link button. when you click on this a dialogue box opens up and you can either enter an extrenal link to another site or you can link to content on your own site.

    when you create a new menu you have access to all the pages and categories (not posts though) and you can just drag na drop the content you want into the menu, save it and then assign the menu to a position in the theme.

    Hi – yes I understand that you can do that however the URL generated is absolute. At the moment the website I’m working on is on a test server and I don’t want to have to go through the site and relink everything once we move it onto the final server.

    Does that make sense?


    On my web sites, i just use that shortcode, so when i move site to another domain, all the links i added manually still work. (presuming that permalink structure is the same)

    Actually, zex2911 – that solution seems to generate the URL slightly wrong…

    The URL I need to be created is e.g.

    and the following is being created instead…

    Any ideas?

    what’s set up to be the home page for your dev site? and i can’t access it for some reason, google keeps on saying page doesn’t exist…

    Yes – I changed the URL as I didn’t want to publish it live whilst we’re still working on it for the client – they want a big reveal you see!

    I’ve a static page set as my home page… eventually it’ll all be in – perhaps it’s the folder structure of the server set up that’s screwing it up…?

    when you set up front page to be, [url] shortcode will work. So if you want to link to, you will have to write it like [url]/categories/latest-news
    I don’t understand why it’s not working on your site, because if you did set up your home page to be, and then created categories, pages, posts, they will all link to that home page.
    I’m working on a web site with home page, and when we move it to the proper domain, [url] thingy will automatically change it to new domain (new home page). Hope that makes some sense… 🙂

    Hmm… very odd indeed.

    I’ve managed to do it via this though following on from your comment.

    <?php echo home_url(); ?>

    Which works fine 🙂

    Thanks for the help.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Linking to pages within site’ is closed to new replies.