237

GitHub wikis allow you to link to other pages in the wiki like so:

[[Wiki Page Name]]

However, I want to display different text than the wiki page name when making the link. Is there a way to do this? Am I linking to wiki pages all wrong?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TaylorOtwell
  • 7,177
  • 7
  • 32
  • 42
  • 2
    Although markdown is not a programming language, we have plenty of questions tagged XML (another markup language) on StackOverflow. I didn't check but I bet there are some on data exchange formats like JSON. Why not allow this question? – Jasper Blues May 11 '22 at 00:18

5 Answers5

331

Using the Markdown link syntax

[Link Text](WikiPage)

seems to work in the edit preview but not on the actual wiki page. At least for me the generated link is WikiPage instead of wiki/WikiPage and I get the famous GitHub 404.

However the MediaWiki syntax

[[Link Text|WikiPage]]

works for me, even for Markdown wiki pages.

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
Sven Jacobs
  • 6,278
  • 5
  • 33
  • 39
  • 1
    This does seem to work consistently, even though it's not in Github's markup documentation. See my comment on @cbley's answer for why his solution seems to work sometimes but not others. – mltsy Jul 18 '12 at 17:19
  • 5
    Further, if the link text and Wiki page are the same, you can simply use: `[[My Wonderful Wiki Page]]`. This will link to `wiki/My-Wonderful-Wiki-Page`. – Jimothy Apr 04 '13 at 12:44
  • 7
    Yes, `[[Link Text|WikiPage]]` works for me. Pleas edit your answer – Anton Danilchenko Apr 15 '13 at 12:31
  • @AntonDanilchenko You mean the other way around? First link text then wiki page name separated by a pipe? – Sven Jacobs Apr 16 '13 at 14:29
  • @AntonDanilchenko I just noticed that my answer has been edited on Mar 5. In my initial post I had the link the other way around like you suggested. The "corrected" link may be valid MediaWiki syntax but I wonder if it has been tested with the GitHub wiki flavor? – Sven Jacobs Apr 16 '13 at 14:41
  • 2
    Here is a reference to [Add links to wikis](https://help.github.com/articles/adding-links-to-wikis/) – Ricardo Nov 13 '14 at 21:27
  • 2
    Note that, as of March, 2019, while MediaWiki syntax works for links with *plain text* as the link text, it breaks when asked to parse link text with any formatting, whether Markdown or MediaWiki syntax. For example, ``` [[Description of `foo`|Foo]] ``` will render the (code-formatted) source markup, not the intended link. If anyone knows a way around this, please let me know. – Jeff Dickey Mar 02 '19 at 06:19
  • The MediaWiki link works in HTML tags, whereas the Markdown syntax does not. – Paul Wintz Dec 02 '22 at 22:52
98

GitHub by default uses Markdown syntax for the wikis so you can just do:

[Arbitrary Link Text](Wiki Page Name)

Check out Markdown and this blog post for more information about their wikis and the other markup syntaxes they support.

This solution has issues when you're on the home page because it creates relative URLs. Check out Sven's answer, below.

Community
  • 1
  • 1
cbley
  • 1,695
  • 12
  • 8
  • 2
    Wikis don't use GFM, just normal markdown. – Tekkub Jun 25 '11 at 01:12
  • 31
    @Sven's answer is correct, this answer is wrong. – Jon Cram Jul 11 '12 at 10:56
  • 25
    This creates a relative url link, so if you happen to be in the same directory as the page you're trying to link to it works, otherwise, it does not. Specifically, if you'er on the Home page (http://.../project_name/wiki), this won't work, because all other pages are in the wiki directory, whereas the homepage isn't. – mltsy Jul 18 '12 at 17:17
  • 4
    -1 since it breaks; Needs to be updated to include last comment on this thread and I'll change to +1. – Merlyn Morgan-Graham Jan 21 '13 at 02:37
  • 10
    Yes, `[[Link Text|WikiPage]]` works for me. Pleas add to your answer – Anton Danilchenko Apr 15 '13 at 12:34
  • -1 since it fails from a saved page but works in preview mode. The preview page is `project/wiki/_preview`, so `[foo|bar]` generates the link `project/wiki/bar` which succeeds. But the saved wiki is just `project/wiki` and the link takes you to `project/bar` which results in a 404. As others have suggested `[[foo|bar]]` links to `project/wiki/bar` in both preview and from the saved page. – cod3monk3y Jul 10 '13 at 17:49
  • 2
    This answer is not correct. Why is it marked as correct and why does it have so many up votes? @Sven's answer is correct below. – Tyler Jones Nov 08 '13 at 14:02
  • 7
    As of May 2014, this appears to have been fixed on GitHub. This answer now works on all pages. However, the preview is still broken. – drhagen May 09 '14 at 21:20
  • 1
    As of August 2019, this doesn't even work in the preview. – ash Aug 16 '19 at 14:39
  • Note that "Wiki Page Name" is not the title but what you see in the url. So "Some Page Name" becomes "Some-Page-Name". – Vitaly Sazanovich Jun 22 '22 at 08:08
40

The internal-ref part is relative to your project. For wiki pages use:

[Page Name](wiki/Page-Name)

In the preview the link will be broken but when the page is saved it will work.

Brett
  • 1,223
  • 13
  • 8
  • 2
    Works but Sven's answer works better. – Ulrich Stern Feb 28 '16 at 18:35
  • 5
    There is a problem with this when using inside a custom sidebar, if you navigate to one of your link, like `wiki/Page-Name`, then in the `wiki/Page-Name` page's sidebar, links are broken having a double `wiki` element like `wiki/wiki/Page-Name`. – Matt Jan 18 '17 at 18:36
  • This does not work within `...` tags whereas `[[Link text|Page Name]]` does. – Paul Wintz Dec 02 '22 at 22:44
  • When I include "wiki/", the resulting link includes "wiki/wiki/Page-Name". – Paul Wintz Dec 02 '22 at 22:48
2
  • The most common use [Link Text](WikiPageURL)
  • The second way: [[Link Text|WikiPageURL]]
  • The third way, if you do not want to repeat and need to use the hyperlink several times: [Link Text] and at the end of the page use once [Link Text]:WikiPageURL
bim
  • 612
  • 7
  • 18
-8

Check the wiki editor's help. It tells you:

To create a reference link, use two sets of square brackets. [my internal link][internal-ref] will link to the internal reference internal-ref.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tekkub
  • 30,739
  • 2
  • 30
  • 20
  • 2
    I also saw that, but it does not work, because - as cbley mentioned - Markdown requires round brackets around internal-ref. I wonder why the help contains wrong information. – Ethan Leroy Dec 08 '11 at 00:35
  • 2
    The wiki's help editor does say that, but "internal reference" in this case refers to an in-page Markdown reference, not another page in the same wiki. See the [Markdown link syntax](http://daringfireball.net/projects/markdown/syntax.php#link) for more info. – Calrion Jul 12 '12 at 02:12