WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Changing the #more-ID anchor for Read more... link (5 posts)

  1. Maujor
    Member
    Posted 8 years ago #

    Hi all,
    I use the quicktag more <!--more--> for display the first paragraph of the post on the index.php

    So, I get the "Read more..." or "Continue reading..." link that points to the whole post. That link, points to an anchor in the post-usually named #more-ID that goes to the 2nd paragraph in the page's post.

    Question is: How to change the link to the very top of the page? (Say to the id of the title post - ususally something like <h2 id="post-#>Post title</h2>

    I need replace the anchor #more-ID by #post-ID

    Thanks

  2. Austin Matzko
    Member
    Posted 8 years ago #

    Add this to your theme's functions.php file or put it in a plugin:

    function replace_the_more($content) {
    return preg_replace('/\#more-(\d)/',"#post-$1",$content);
    }
    add_filter('the_content','replace_the_more');

  3. Maujor
    Member
    Posted 8 years ago #

    Hello filosofo,
    Plugin option works like a charm, :-)
    Thanks for share.
    ---------------------------------------------
    For further information, sharing with others:
    The plugin code:
    <?php
    /*
    Plugin Name: more_replace
    Description: Replace de #more-ID anchor by #post-ID anchor.
    Author: Filosofo
    Author URI: http://www.ilfilosofo.com/blog
    Plugin URI: http://wordpress.org/support/topic/72388?replies=2#post-378516
    */
    your code here...
    ?>

  4. Chris_K
    Member
    Posted 8 years ago #

    Just for ref, here's a plugin that already existed:
    http://www.viper007bond.com/wordpress-plugins/more-to-the-top/

  5. cwd
    Member
    Posted 7 years ago #

    Is there a case where a page contains more than one article? That would explain the #post-ID in the url. If it's only one article per page, wouldn't this be just as good?

    function replace_the_more($content) {
    return preg_replace('/#more-(d)/','',$content);
    }
    add_filter('the_content','replace_the_more');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.