"

19 Hyperlinks

External

You can add a link to any external website using the Visual editor, or the Code editor.

Visual Editor

Here is how you add a link in the Visual Editor:

  • Write some text
  • Highlight the text
  • Click on the Link icon in the toolbar
  • Add your link by clicking the enter button
Image of the visual editor demonstrating how to add a hyperlink.
Figure 1. Pasting a link in the visual editor.
Image of the "Insert/edit link" screen in Pressbooks with the option to change link text and URL.
Figure 2. Editing a link in the visual editor.

Code Editor

Using the Code Editor, the format should be:

This <a href="http://somesite.com">text has a link</a> and then goes on.

Internal

You can also link to other items within your book, for instance from one chapter to another. The difference when you are linking internally, rather than to a web page as you might be used to, is that you don’t have a URL in the traditional sense. Instead, you need to use the identifier (called a slug) of an internal location, of which there can be two kinds: default locations and locations that you create yourself. Both of these are used to indicate an exact point in your document. Here’s how you do it:

Default Internal Links

When you create a document, there are already some identifiers that will be understood. For example, if you want to link to a chapter, you simply need to enter:

[book-title-here]/chapter/[your-chapter-title-here]

 

To link to a part, enter:

[book-title-here]/part/[your-part-title-here]

 

To link to a front matter section, enter:

[book-title-here]/front-matter/[your-section-title-here]

 

To link to a back matter section, enter:

[book-title-here]/back-matter/[your-section-title-here]

 

The easiest way to find this location identifier is to look at the URL of a page in the web version of your book and copy everything that comes after .edu (including the forward slash).

The link tool in the Visual and Code Editor toolbars will also let you scan through all existing parts, chapters, front matter, and back matter in your book and choose one to link to. To select your internal link with this option:

  1. Highlight the text you want to hyperlink
  2. Select the link tool
  3. Click the gear icon on the link toolbar labeled Link Options and wait for the Insert/edit Link window to appear (the window will pop right up in the Code Editor without needing to click on the gear icon)
  4. Scroll through existing posts in your book and select the one you wish to link to
  5. Click “Add Link”

If the chapter is still in draft, just look at the permalink below the chapter title and copy everything that comes after .edu (including the forward slash).

 

Create Custom Internal Links Using Anchors

In order to create links between more than just chapters or parts, you can create custom location tags that you can then link to from anywhere in your book.

Let’s say you’re writing a section of your book and want to link to a section in an earlier chapter:

  1. Go to the chapter
  2. Find the section heading
  3. Place your cursor at the start of the heading and click on the Anchor button on the toolbar (it looks like a bookmark)
  4. Enter a name when prompted (this must be unique).
  5. You now have an anchor tag at the start of your heading and should see it appear as a small icon.
Image of the anchor icon in the visual editor toolbar in Pressbooks.
Figure 3. The anchor icon in the visual editor toolbar.
Image of the anchor icon being used in the visual editor next to a section heading.
Figure 4. What an anchor looks like in the visual editor.

To link to it, go back to your chapter in progress, and follow the instructions above to create a link. When it prompts you to enter a URL, enter:

/chapter/chapter name/anchored section

The link tool will also let you scan through all existing anchors in your book and choose one to link to. To select your internal link with this option:

  1. Highlight the text you want to hyperlink
  2. Select the link tool
  3. Click the gear icon on the link toolbar labeled Link Options and wait for the Insert/edit Link window to appear
  4. Scroll through existing posts and anchors in your book and select the anchor you wish to link to
  5. Click “Add Link”

Note that if you’ve imported your text from a Word document, any footnotes that were in the original document may also have left anchors in your book. These anchors will display as link options in the Insert/edit Link window.

 

Uses for Custom Internal Links

  • Link to figures from main body text and vice versa, e.g., “See Figure 1”
    • NOTE: to add an anchor tag to an image caption, you must add it manually in the image editing window, not the visual editor. Simply enter the caption as <a id=”[your-id]”></a>[Your Caption]
  • Link to chapter sub-sections.
  • Link to specific sections of back matter.
  • Link between chapter sections and their related exercises.

 

Slugs

The identifiers we used above are commonly referred to as slugs. These are automatically generated for every section of your book you create, and they can be found by looking at the page’s URL. However, sometimes you might need to edit them. To do so:

  1. Go into the chapter or section whose slug you want to edit.
  2. Find the Screen Options tab in the top right corner of your screen.
  3. Check the Slug option.
  4. Click on Screen Options again to collapse the tab.
Image showing the Screen Options menu in Pressbooks
Figure 5. Screen Options menu in Pressbooks.
Image highlighting the Slug section in the Pressbooks editor.
Figure 6. Where to find the Slug section in the Pressbooks editor.
  1. Scroll down to below the visual/code editor to find the Slug section.
  2. Enter your new slug.
  3. Save or update your chapter.

 

This is a handy trick for a few reasons:

  • If you have a long chapter name, shortening the slug can make it more manageable.
  • If you start your title with a number (eg. “1. Program Overview”), your exports will add the word ‘chapter’ or ‘part’ to the front of the slug, which will break your links to that location. Use the slug editor to make sure your slugs start with a word, not a number.
  • If you name both a part and a chapter the same thing, the exports will again add something to distinguish them from each other, breaking the links. Use the slug editor to make sure they’re different from each other.

 

License

Icon for the Creative Commons Attribution 4.0 International License

Getting Started with Open Educational Resources Copyright © 2019 by Mahrya Burnett, Jenay Solomon, Heather Healy is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.