Help:Link#Pipe trick

{{Short description|Wikimedia help page}}

{{pp-semi-indef|small=yes}}

{{Redirect|H:L|help with lists|Help:List}}

{{About|how to mark up links|a very basic tutorial|Wikipedia:Tutorial/Wikipedia links|various URLs of Wikipedia and other Wikimedia servers|Help:URL}}

{{Wikipedia how to|H:L|H:LINK}}

{{Linking and page manipulation|linking and diffs}}

File:How to make a wikilink.webm

This page explains how to make the wikilink, interwiki link, or external web link (as hyperlinks) connections on Wikipedia, which gives readers one-click access to other Wikipedia pages, other Wikimedia projects, and external websites.

A link has various (changeable) appearances on the "anchor" page, and the "target" page, which owns the "backlinks", and which can count the links to it with the WP:What links here tool.

For a short list of some basic shortcuts, see Wikipedia:Cheatsheet.

For guidelines on how links should be used in Wikipedia, see Wikipedia:Manual of Style/Linking.

= <span id="Http: and https:">http: and https:</span> =

[https://blog.wikimedia.org/2015/06/12/securing-wikimedia-sites-with-https/ In mid-2015], Wikipedia and all other Wikimedia sites were changed to use HTTPS to encrypt all traffic. Accessing a URL like http://en.wikipedia.org/wiki/Help:Link will result in the webserver redirecting you to [https://en.wikipedia.org/wiki/Help:Link https://en.wikipedia.org/wiki/Help:Link]. Therefore, when making an external-style link to an internal page (that is, using single square brackets, or a bare URL), https should be specified to avoid the needless redirect, as in https://en.wikipedia.org/w/index.php?title=Help:Link&action=history.

In the past, when Wikipedia could be accessed via either HTTP or HTTPS, a protocol-relative URL could be used to make an external link (or external-style link to an internal page) which would use http: or https: depending on how the page the link appeared on was accessed, as in [//www.mediawiki.org/wiki/Help:Links]. However, as all Wikimedia sites now require HTTPS, this linking style is obsolete and should no longer be used. http: or https: should be explicitly specified as appropriate for the target site (preferring https:, where available).

What is an "anchor"?

{{sh|WP:ANCHOR DEF}}

The word "anchor" has two opposite meanings.

In the context of a link from an anchor to a target, it is the starting place.

In the context of the {{tl|anchor}} template, an "anchor" is a landing place for a link to jump to. The anchor template automatically creates some invisible coding from certain text in the template in the "landing place". In this context, the word "anchor" may refer to:

  • the text and parameters, in the template, from which the invisible code is created,
  • the mostly invisible HTML code, or
  • the landing place/location/spot in itself.

Section linking (anchors)

{{shortcut|WP:ANCHOR}}

{{see also|Help:Section#Section linking|Wikipedia:Manual of Style/Linking#Section links}}

To link to a section or subsection in another page, append a # and the section name to the page name:

:{{nowrap|displayed text}}

For linking in the same page, omit the page name and use a # and the section name:

:{{nowrap|displayed text}}

Omitting the page name is recommended when linking to a section in the same page because the link will work as expected when previewing changes or after moving the page.

To format a link with the section sign (§) instead of a # (e.g. {{section link|Page name|Section name}} rather than Page name#Section name), use the template {{tl|Section link}} (or {{tl|slink}}):

:{{nowrap|{{Section link|Page name|Section name}}}}

Note that Section names are entirely case sensitive, in contrast to article links, where the first letter is not case sensitive.

The characters [ ] { | } require encoding when linking to a section:

class="wikitable"

! [ !! ] !! { !! | !! }

.5B.5D.7B.7C.7D

For example, the section "[Closed] Complaint" can be linked with #.5BClosed.5D Complaint. Links in the table of contents will automatically make this encoding, so the URL can be copied from there. However, that URL will also encode other characters which do not interfere with templates or wikicode, so the result may look ugly.

For more information, see Help:Section. See also {{slink|Wikipedia:Redirect|Targeted and untargeted redirects}}.

=Specifics=

When a link contains a section title (as in the examples above), the title actually points to an HTML anchor on the target page. In addition to anchors created automatically by section titles, there are times when it's advantageous to create an anchor on a smaller unit of text, such as a specific paragraph (see {{section link ||Linking to part of a section}} below). This can be done using {{tl2|Anchor|anchor name}}, or alternatively, the HTML code {{nowrap|...}} (see {{tl|Anchor}} syntax). Anchors are also used when renaming a section, yet still allowing links to the old name to function, or similarly, allowing linking to a section using an abbreviation; see MOS:HEADINGS for more info. Links to anchors can also be added to external URLs and to interwiki links, again using the # syntax.

Section links still work through page names that are redirects. For example, if Danzig redirects to Gdańsk, then Danzig#History will link to the "History" section of the article Gdańsk. It is also possible for the target of a redirect to be defined as a specific section or anchor of a page (these work only if JavaScript is enabled). Indeed, according to the Manual of Style, it may be preferable to define such redirects, and use them when linking to those sections/anchors, rather than linking using the {{nowrap |displayed text}} or {{nowrap |{{Section link|Page name|Section name}}}} syntax. This way, if the section or anchored text later becomes its own article, links via the redirect won't need to be rewritten.

For example, Wikipedia:Section link redirects specifically to the section Help:Link#Section linking (anchors) on this page. A quirk of the way this works is that if one were to add a section name when using such a link, it would override the section specified by the redirect. So Wikipedia:Section link#Interwiki links would go to the "Interwiki links" section of this page. Such overriding of section redirects should be avoided.

The {{tl|Visible anchor}} template can be used to create {{visible anchor|Visible anchor example|text=an anchor that is highlighted when is linked to}} (click here for an example). The template's first parameter will be used as both the anchor and the display text ({{para|text}} can be used to provide different display text).

=Duplicate section names=

{{Shortcut|WP:DUPSECTNAME}}

If more than one section on a destination page has the same title, a link to the title is to the first section with that title. If the link should be to another section with the title or a title that differs only in capitalization (Example vs. EXAMPLE), append to the linked title _2, _3, and so on, without a space (or 2, 3, and so on with a space), counting from the top of the destination page and without regard to whether a section is a section or a subsection. For example, multiple sections titled "History" may be linked to as "History", "History_2" (or "History 2"), and so on.

=Linking to part of a section=

{{shortcut|WP:LINKPART}}

{{see also|#Table row linking}}

Anchors can also be used to link to any part of a section. For example, if you want to link to the fifth sentence of a section, you place an anchor at the start of that sentence, and you can then link to that anchor in the same way as you would link to any other anchor.

However, just as with section names, duplicate anchor names only link to the first one. Since anchors aren't displayed you have a much greater freedom in picking unique anchors, such as by appending the current date and time to the anchor name (for example, by naming an anchor for section "ThisSection" like so: {{Anchor|ThisSection2014-09-22-18-05a1}} ).

Anchors can be placed anywhere, including at the start of a clause, and inside notes and citations, though it is advisable to test first in your sandbox before trying some exotic new kind of location for the first time. Also the anchor has to be placed after any indicators that are only recognized at the start of a line (such as == or ===, etc., for new section, * for new bullet point, : for indentation), as the anchor should still work, but the start-of-line indicator usually no longer will (and you may not always notice this, perhaps especially if you are in a hurry).

There are a small number of special anchor names. See {{slink|#Table row linking}}.

Table row linking

To create an anchor for a row of a table, see {{slink|Help:Tables and locations#Section_link_or_map_link_to_a_row_anchor}}. However, #top and #toc are reserved names that link to the top of a page and the table of contents, respectively.

= Using a redirect as alternative =

An alternative to a piped link is using redirect pages. For example, to create How to set up a coffee house, use How to set up a coffee house and make this a redirect to coffeehouse setup. This is convenient if the redirect is already there or will also be of use elsewhere; however, there are a few drawbacks:

  • The tooltip does not show the page one will arrive at.
  • "Related changes" gives the changes in the redirect page, not the redirect target.

Combining a piped link and a redirect, one can provide some information that is not the name of the page one links to in the hover tooltip, e.g., the pipe to a redirect UNO will display a tooltip "United Nations Organization" when hovering over UNO, thereby explaining the abbreviation. (However, {{tl|abbr}} is preferred for abbreviations.)

= Automatic conversion of wikitext with the pipe trick =

{{See also|Help:Pipe trick}}

If in a piped link the part after the "|" is left empty, it is converted to an abbreviated form of the linked page, as follows:

  1. Any word before the first colon (:), as well as the colon itself, is removed. This word may or may not be a namespace prefix (such as "Help:") or an interwiki prefix (such as "commons:"). If the page name is preceded by a colon, "first" refers to "first after this".
  2. If there is text in parentheses at the end it will be removed.
  3. If there are no parentheses but there is a comma, the comma and everything after it are removed.
  4. The link will be in whatever case is used.

Just like for the three or four tildes when signing on Talk pages and the use of subst, in a preview, the result already shows up in the preview itself, but the conversion in the edit box is not yet shown. Press "Show changes" to see the change in the wikitext.

;Category tag

:The sort key syntax of the category being like a piped link, the pipe trick also works for category tags, even though it is not useful there.

;Examples using colons

: is converted to Template, which is rendered as Template.

: is converted to My life, which is rendered as My life – although "Music:" is not a namespace (therefore the space after the colon is not automatically removed), the shortcut works anyway.

: is converted to en:Pipe, which is rendered as en:Pipe.

;Case examples

: is converted to pipe which is rendered as pipe.

: is converted to Pipe which is rendered as Pipe.

;Comma example

: is converted to Boston, which is rendered as Boston.

;Other examples

:Parameters and variables:

: does not give {{{1}}}.

: Calling the template with a value of parameter 1 gives a working link in the case of substitution only.

: does not give en:{{FULLPAGENAME}}.

: does not give {{FULLPAGENAME}}

These examples appear as:

= Inverse pipe trick =

On page "A (c)", B is automatically converted to B.

Similarly, on page "A, c", B is automatically converted to B.

Further examples are here.

Hover tooltips

In many browsers, holding the cursor over a link (mouseover) shows a hover tooltip containing the text of the link's HTML title attribute. MediaWiki – the software which runs Wikipedia – sets this to the target page name (without any section indication) if it's a wikilink, the page name with prefix if it's an interwiki link, and the link address (URL) if it's an external link. (This can be switched off in the user preferences.) The browser may also show similar information, including any section indication, in the status bar.

For these effects a piped link is useful even if it is not followed; for example, for displaying the meaning of an acronym. It is possible to produce a hover tooltip without a link, using the {{tl|Tooltip}} template.

Disallowed characters

A link whose target contains disallowed characters (see WP:Page name) will be displayed without markup, as in A{b}.

Conversions are automatically made to non-literal characters in wiki and interwiki links. For example, Help:Page%20name becomes Help:Page name. However, the opposite is true for external links; literal characters are converted into non-literal characters. For example, most browsers convert .../wiki/! to .../wiki/%21.

Some characters in a web address link need to be represented as escape characters because they are reserved for Wikipedia edits. Examples include %5B for [, %5D for ], %3C for <, %3E for >, %7B for {, %7D for }, %7C for |, and %26 for &. More can be found by reading about percent encoding. Numeric character references (e.g. &#91; or &#x5B;) should not be used in external links because the ampersand character (&) has a special meaning in a URL.

In excessive cases, an automatic [https://www.w3schools.com/tags/ref_urlencode.ASP percent encoder such as the one at W3 Schools] (use the second JavaScript form under "URL Encoding Functions") is probably the simplest solution. For example, pasting Help talk:Citation Style 1/Archive 41#{{Cite book}} and |contribution problems into that form yields the wikilink Help%20talk%3ACitation%20Style%201%2FArchive%2041%23%7B%7BCite%20book%7D%7D%20and%20%7Ccontribution%20problems, which appears as Help%20talk%3ACitation%20Style%201%2FArchive%2041%23%7B%7BCite%20book%7D%7D%20and%20%7Ccontribution%20problems, as desired.Note that this wikitext isn't as pretty as the manual method, which would yield Help talk:Citation Style 1/Archive 41#%7B%7BCite book%7D%7D and %7Ccontribution problems. This is because the encoder converts characters like space, :, and # which are legal in wikilinks and don't need to be converted.

{{anchor|Links containing URL query strings}}

= Links containing ampersands =

Because the ampersand character (&) is disallowed, it is not possible to create an ordinary link containing &action=edit or &redirect=no in the URL query string. These kinds of links can be helpful in user pages. Also, a redirect page can have categories and you might wish to view or edit these in a single click. There are three ways to create these links:

  • You can use the {{tl|Querylink}} template to append query parameters to a Wikipedia page URL. For example, {{Querylink|Help:Link|qs=action=history|this page's history}} produces the link {{Querylink|Help:Link|qs=action=history|this page's history}}.
  • You can use the {{tl|Plain link}} template to encode a Wikimedia url link. For example,{{Plain link|url=https://en.wikipedia.org/w/index.php?title=Special:Log&logid=79269392|name=query}} yields the link {{plain link|url=https://en.wikipedia.org/w/index.php?title=Special:Log&logid=79269392|name=query}}.
  • You can use the magic word fullurl. For example, to append action=edit to a URL query string you could use [{{fullurl:Help:Link|action=history}} this page's history], which renders as [{{fullurl:Help:Link|action=history}} this page's history]. Note that this will render as an external link rather than as an internal link and for this reason it might not appear in what-links-here queries associated with the target page.

Link reports

{{more|Help:What links here}}

The navigable links to a page are wikilinks, redirects, and external-styled wikilinks.

The {{tl|orphan}} tag can be placed on pages with no incoming wikilinks.

= To a page =

Each link to a page is a link to a name.

The aliases for the namespace part of the name are recognized in

wikilinks and in the parser functions that create URL style links – canonicalurl and fullurl.

They are also recognized in the navigation box, and in Search,

except for the insource parameter.

No one report shows all links to the content.

The What links here tool, on every page,

will report all wikilinks and all redirects to the content of that page.

(You get the wikilinks to the redirects too.)

The search parameter linksto will find wikilinks only.

Both report (invisible) wikilinks placed by a transclusion through a {{template}}.

The difference between them is that linksto reports a count of links to a page name,

while WhatLinksHere reports a map of links to the page as content.

"What Links Here" does not report URL-style links to a page.

= To a section =

The navigable links to a section of a page are wikilinks, redirects, and URL-styled wikilinks.

The difference between a redirect and a wikilink is most pronounced where a redirect targets a section,

when you cannot add your own #section{{space}} to it

even though it appears as [[page name]].

A wikilink that links to a section and that appears as [[page name#section name]]

can link to that section through the canonical page name (the title on the page with the actual content)

or through the page name of any redirect to it, in which case the page name is the name of a redirect page.

To find wikilinks to a section requires two or more reports.

  1. Show redirects only, an external tool available from the What links here page, reports redirects to the content of a section. (No matter which page name you give it, you get all the redirect page names.) Look past any "No anchor or section" group of redirects, and any "invalid" sections, to see if your particular section name is explicitly listed, because then the redirect pages under it can have incoming links that will then go to that section. Redirects that link to a section are part of a valiant effort to enable changing a section heading without breaking a link to the name. That effort also must ask editors who want to link to a section to always check the wikitext of the target section, and there find, read and understand the plan to link to a single redirect page instead. Then that redirect page links to the section. ("Invalid" redirects to a non-existing anchor or section occur when this is overlooked.) ("What Links Here" also has a "show redirects" report, but it doesn't specify if the redirect goes to any particular section.)
  2. Use "What Links Here" on any redirect pages found in the previous step.
  3. Use {{tl|Links to}} to create a group of search links that will each report some links to a section. It can work with only one page name at a time. For each search link given, just change the page name in the query to each redirect in turn.

The more redirects there are, the more reports there are to run.

If there are no redirects involved, one report from "Links to" is enough.

= From a page =

To report links from a page, you simply list all the wikilinks on that page.

  • {{slink|Wikipedia:Tools/Editing tools|Relink}} can count wikilinks from a copy of the wikitext on your local machine.
  • Some text editors support the counting and highlighting of the [[...]] pattern occurrences.
  • The Wikipedia web API accepts queries by URL.

If you will use the API heavily or professionally you should follow its currently listed recommendations at API.

(Use continue=, use formatversion2, use multiple pages at once, etc.)

One way to send a query to the API is by creating an external link ({{slink||External links}}).

For example, using an external link very much like a search link, you can

send the API a request to list the link properties of "wp:example".

It should interpret it correctly as "Wikipedia:Example", pageid 25263910.

; What you type

:[//en.wikipedia.org/w/api.php?action=query&prop=links&pllimit=500&titles=fullpagename your label]

; What you get when fullpagename is wp:example

:[//en.wikipedia.org/w/api.php?action=query&prop=links&pllimit=500&titles=wp:example your label]

  • The report is in JSON format, as is usual for RESTful APIs.
  • The pageid is available from Page information on every page.
  • The titles parameter is plural. (It is designed to take multiple fullpagenames or pageid, delimited by the | pipe character.)
  • The number of links returned by this query is limited to 500, per the URL you created. See mw:API:Query for how to safely get more. For example, Operating system has 510 wikilinks.

To make a page register as a link to a page, but without actually showing the link,

make a link to it, but label it with a space character using the pipe trick: [[pagename| ]].

Conversion to canonical form

{{See|mw:Manual:Title.php#Canonical forms}}

As described previously, if a link target begins with a lower case letter, it will be interpreted as if it began with the equivalent capital letter. If the target contains a namespace prefix, then the whole prefix and the first character after the colon are case-insensitive (so uSeR:jimbo Wales links to User:Jimbo Wales).

In link targets, spaces and underscores (which are effectively equivalent) are ignored if they come at the start, at the end, or immediately before or after the colon following a namespace prefix. Consecutive spaces / underscores are treated as a single space. Hence _User_: Jimbo_ __ Wales__ links to User:Jimbo Wales.

HTML character references and percent-encoded characters are replaced with their raw character. For example, d&eacute;partement produces département, and %40 produces %40. Links which resolve to invalid page titles are displayed as unmarked-up wikitext.

Titles indicated by wikilinks are displayed in canonical form (with correction of capitalization and excess spaces / underscores removed, as described previously) in the following places:

  • In transclusion tags for non-existent pages: {{qwsazx}} gives Template:Qwsazx.
  • In tooltips and in the status bar (if applicable for the browser) when the mouse cursor is moved over the link.
  • On redirect pages.
  • In the category box.

The prefixes in interwiki links are treated similarly to namespace prefixes: they are insensitive to case and to spaces before and after the colon. However the first character after the colon is not automatically capitalized (whether it is interpreted as a capital depends on the configuration of the target wiki).

See also

Notes and references

{{reflist}}

{{Help navigation}}

{{Wikipedia technical help|collapsed}}