10

1. Question

If I code like the following, then I have a link within the page to a specific "section"

[[#SectionTitle|displayed text]]

But what if I want to have a link within the page to a place, I mean any place?

Sometimes I might want to directly refer to a part of the page that isn't at the start of a section.

2. What I tried

I tried something like this

[[#Foo|displayed text]]
{{anchor|Foo}}

This seemed to ask me to make a page Template:Anchor

So I copied the Template:Anchor page of wikipedia.

But Template:Anchor again seemed to ask to make some new page, because Template:Anchor only says

{{#invoke:anchor|main}}

So my attempt didn't work.

user1849133
  • 527
  • 1
  • 7
  • 18
  • link to official mediawiki help on anchors for section headers: ["Section headings and the top of the page are automatically anchored"](https://www.mediawiki.org/wiki/Help:Links) – Trevor Boyd Smith Oct 18 '16 at 19:25

3 Answers3

15

Use the following to create the anchor:

<div id="NameOfAnchorHere">optional text</div>

which can be referenced as:

[[#NameOfAnchorHere| test]]

More information about linking in MediaWiki can be found here

ebo
  • 2,717
  • 1
  • 27
  • 22
1

And just to explain what's going on with {{#invoke:anchor|main}}: that's using Lua code in the Module namespace to generate the anchor.

Note that it eventually uses

<span id="NameOfAnchorHere">optional text</span>

which, I think, is nearly equivalent of <div style="display:inline;">, I think.

Mark Hurd
  • 10,665
  • 10
  • 68
  • 101
0

Put the closing tag at the end of the paragraph, not right after the anchor. That will then not cause a line break. Or use the span tag which can be immediately after the anchor.

  • Could you please write some example code? I'm also unsure why you're mentioning line breaks, because the original question asker didn't mention that. Does this answer the question? – Ann Kilzer Dec 28 '19 at 02:03