0

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?

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 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 at 18:44

1 Answer 1

1

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.

Step-by-Step Guide to Link Directly to the Title of a Post/Page

1. Modify the Theme Template

  1. 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).
  2. Edit the Single Post/Page Template:

    • Locate the template file for single posts (single.php) or pages (page.php). You may also want to edit header.php if your theme uses a header file for the title.
  3. 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>
      
  4. 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 with https://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
3
  • Wonderful!! Thank you
    – ThomasMox
    Commented Jun 15 at 11:46
  • If it works, please mark it as accepted :)
    – mukto90
    Commented Jun 15 at 12:02
  • It worked! I added an ID tag in the permalink for posts. wp-includes/link-template.php } else { // If they're not using the fancy permalink option. # hack added by RC $permalink = home_url( '?p=' . $post->ID . '#post-title'); }
    – ThomasMox
    Commented Aug 9 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.