admin管理员组文章数量:1122832
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?
Share Improve this question asked Jun 14, 2024 at 14:05 ThomasMoxThomasMox 1 2- It really depends on the theme you're using. If you're using a custom theme, you can add its header and post template code here for help. – WebElaine Commented Jun 14, 2024 at 14:24
- Thank you for answer! Not sure to get the temlate codes. I´m using "twenty sixteen" as just an ordinary blog. URL: blog.mox.se Perhaps I could solve my problem attaching some code to #anchor at the topmost block, making the page load 50-60 px up, the title then showing up? – ThomasMox Commented Jun 14, 2024 at 18:44
1 Answer
Reset to default 1To 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.
Step-by-Step Guide to Link Directly to the Title of a Post/Page
1. Modify the Theme Template
Access Theme Files:
- Connect to your WordPress installation via FTP or use the theme editor in the WordPress admin dashboard.
- Navigate to the theme directory (typically
wp-content/themes/your-theme
).
Edit the Single Post/Page Template:
- Locate the template file for single posts (
single.php
) or pages (page.php
). You may also want to editheader.php
if your theme uses a header file for the title.
- Locate the template file for single posts (
Add an ID to the Title:
Open the
single.php
orpage.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:
- Save the changes to the template file.
- If you edited the file locally, upload it back to the theme directory on your server.
2. Use the Anchor Link
- When you want to link directly to the title of a specific post or page, use the anchor
#post-title
in your URL. - For example, if the URL of your post is
https://example.com/my-post
, you can link directly to the title withhttps://example.com/my-post#post-title
.
Example:
If your post URL is:
https://example.com/my-post
The link to the title will be:
https://example.com/my-post#post-title
本文标签: I want the Title of pagepost to show up topmost when reading the postpage
版权声明:本文标题:I want the Title of pagepost to show up topmost when reading the postpage 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303713a1931979.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论