This is Ben from Compete Themes and in this beginner WordPress tutorial,
you'll learn how to add a link to a part of a page.
You'll start by adding a link to a different section within the same page,
then learn how to link too parts of other pages, and lastly,
you'll learn how to add these special links into your menu.
Let's get started with step one now.
To begin log into your WordPress dashboard and click on the Pages menu.
Once the page loads, click on the page you'd like to add the link to.
In my example, I'll be using this sample page,
but keep in mind that the same technique works for posts too.
Now the link is going to be added the same way you're used to. For instance,
I would normally add a link by highlighting some text,
clicking the link icon,
and then inside the URL input I would enter a full URL that would lead visitors
to another webpage when they click it. The question is,
how do you modify this link so that when a visitor clicks it,
it takes them to a specific part of the page you're linking to?
In my example,
I want visitors who click this text here to be taken to the "learn more" heading
down here. To do that,
I need to give the heading what's called an "anchor" and then link to that
anchor. Here's how to do that.
Start by clicking on the heading and you'll see a set of options for the heading
block appear in the right sidebar. Next,
click on the Advanced section and you'll see this HTML Anchor field at the top.
You can name the anchor whatever you want,
but in my case I'll call it "learn-more." It's best to use all lowercase letters
and make sure to replace any spaces with hyphens. Now that the anchor is added,
I'll scroll back up to the text I want to link, then I'll highlight it,
and click on the link icon. Instead of entering a complete URL,
add a hashtag followed by the name of the anchor. And then when you're done,
press Enter to save your change.
I'll update the page now and then click View Page and once the page is finished
loading,
I'll click on the link and as you can see I've been taken instantly to the
heading. In my example, I've linked to a section on the same page,
but you can use the same technique to link to a section in a different page.
To do that,
you'll enter the complete URL just like you normally would and then add the
anchor at the end like this.
Now when a visitor clicks this link,
they'll be taken straight to this section within the page you've linked to.
In my examples so far I've been looking to headings because they have the anchor
option available in the sidebar, but you don't have to only link to headings.
You can use any block you want if you edit the HTML. For example,
you can click on a paragraph block, then click the options button,
and choose edit as HTML.
Then inside this opening "p" tag,
type out "id=" and then in quotes the name of the anchor.
When you click away from the paragraph,
WordPress is gonna get bothered by this and force you to leave the block as
HTML. So just click the "Convert to HTML" button when you're finished.
It's kind of a pain and I hope they do change this in the future,
but it works fine this way.
Now you can link anyone to this paragraph as long as you use the anchor that you
named here. And as I explained earlier,
you would do that with a hashtag followed by the name of the anchor right here.
Lastly, you can use the same exact technique in your menu.
Hover over the Appearance menu and click Customize to reach the Live Customizer,
and once the page loads,
open the Menus section near the bottom I've got this "Primary" menu which I'll
select, and then I'll click the Add Items button to include the new link.
To add the new link, click the Custom Link section at the top,
and here you'll enter in the complete URL of the page you want to link to.
And then just like in the last example,
you'd add the hashtag and the name of the anger at the end. And with that,
you can now add links to specific parts of any page you want from within your
posts and pages or from a menu item.
That's everything you need to know about linking within your WordPress pages,
and if you enjoyed my tutorial then make sure to subscribe so you can catch the
next one too. If you have any questions,
please post in the comments section below, and as always,
thanks so much for watching.