I want the Title of page/post (in content area) to show up topmost when reading the post/page.
If you use #anchor link you can only link to the topmost textblock, but then the Title of the post becomes hidden above.
How to link it to the Title?
I want the Title of page/post (in content area) to show up topmost when reading the post/page.
If you use #anchor link you can only link to the topmost textblock, but then the Title of the post becomes hidden above.
How to link it to the Title?
To ensure the title of the page or post is displayed at the top when linked with an anchor, you need to adjust the HTML structure of your WordPress theme slightly. The title should be placed within an anchor element that can be targeted.
Access Theme Files:
wp-content/themes/your-theme
).Edit the Single Post/Page Template:
single.php
) or pages (page.php
). You may also want to edit header.php
if your theme uses a header file for the title.Add an ID to the Title:
Open the single.php
or page.php
file in a text editor.
Find the code that displays the title, which usually looks something like this:
<h1 class="entry-title"><?php the_title(); ?></h1>
Add an id
attribute to the title element:
<h1 class="entry-title" id="post-title"><?php the_title(); ?></h1>
Save and Upload the Modified Template:
#post-title
in your URL.https://example.com/my-post
, you can link directly to the title with https://example.com/my-post#post-title
.If your post URL is:
https://example.com/my-post
The link to the title will be:
https://example.com/my-post#post-title