• Resolved vikkineal

    (@vikkineal)


    Hi

    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)

    http://s391121684.websitehome.co.uk/themename/category/latest-news/

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

    Any suggestions?

    Ta

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) {
    	extract(shortcode_atts(array(
    		"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

    (@theotherlebowski)

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

    Thread Starter vikkineal

    (@vikkineal)

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

    jack randall

    (@theotherlebowski)

    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.

    Thread Starter vikkineal

    (@vikkineal)

    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?

    Thanks

    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)

    Thread Starter vikkineal

    (@vikkineal)

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

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

    http://s391121684.websitehome.co.uk/mySite/category/latest-news/

    and the following is being created instead…

    http://s391121684.websitehome.co.uk/mySite/the-new-7-1m-sealegs-touches-down-in-poole/%5Burl%5D/category/latest-news/

    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…

    Thread Starter vikkineal

    (@vikkineal)

    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 http://www.mySite.co.uk – perhaps it’s the folder structure of the server set up that’s screwing it up…?

    when you set up front page to be http://www.mysite.co.uk, [url] shortcode will work. So if you want to link to http://www.mysite.co.uk/categories/latest-news, 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 http://s391121684.websitehome.co.uk/mySite/, and then created categories, pages, posts, they will all link to that home page.
    I’m working on a web site with home page http://mediastack.org/lic2, 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… 🙂

    Thread Starter vikkineal

    (@vikkineal)

    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.