WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Linking to pages within site (12 posts)

  1. vikkineal
    Member
    Posted 1 year ago #

    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

  2. zex2911
    Member
    Posted 1 year ago #

    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>
  3. theotherlebowski
    Member
    Posted 1 year ago #

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

  4. vikkineal
    Member
    Posted 1 year ago #

    zex2911 - yes i think that's what i need! Thank you

  5. theotherlebowski
    Member
    Posted 1 year ago #

    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.

  6. vikkineal
    Member
    Posted 1 year ago #

    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

  7. zex2911
    Member
    Posted 1 year ago #

    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)

  8. vikkineal
    Member
    Posted 1 year ago #

    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/url/category/latest-news/

    Any ideas?

  9. zex2911
    Member
    Posted 1 year ago #

    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...

  10. vikkineal
    Member
    Posted 1 year ago #

    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...?

  11. zex2911
    Member
    Posted 1 year ago #

    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... :)

  12. vikkineal
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags