• Resolved maujor

    (@maujor)


    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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');

    Thread Starter maujor

    (@maujor)

    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: https://www.ilfilosofo.com/blog
    Plugin URI: https://www.ads-software.com/support/topic/72388?replies=2#post-378516
    */
    your code here...
    ?>

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

    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');

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing the #more-ID anchor for Read more… link’ is closed to new replies.