Forums

[resolved] Change more tag url (5 posts)

  1. kjeft
    Member
    Posted 1 year ago #

    I am trying to change the url my 'read more' tags are pointing to, using this code on my custom pages:

    <?php global $more;
    $more = 0;
    the_content('<span id="more-text"> Read more...</span>',FALSE,'http://www.google.com'); ?>

    Any ideas why it is not working?

  2. vtxyzzy
    Member
    Posted 1 year ago #

    I am just going through the same thing - the documentation is totally bogus. The third parameter is not even passed to the_content in 3.0, and ignored in 2.8 and 2.9 (at least).

    I am working on a fix using the_content_more_link filter, but so far no luck.

  3. vtxyzzy
    Member
    Posted 1 year ago #

    This seems to work on the_content(). I was fighting with the_excerpt() until I figured out that the twentyten theme registers a filter for get_the_excerpt that was sticking a link in with the default text. I guess I will have to override that one, too.

    Stick this function somewhere ahead of the call to the_content().

    <?php
       // Replace the_content more link with a global value, if it exists.
       function mam_content_more_link_filter ($link,$link_text) {
         global $mam_global_fix_this_more_link;
         if ($mam_global_fix_this_more_link) {
           $link = $mam_global_fix_this_more_link;
         }
         return $link;
       }
    add_filter('the_content_more_link','mam_content_more_link_filter',10,2);
    ?>

    Then, define $mam_global_fix_this_more_link and set it to the value you want for the entire link - < a tag and all:

    <?php global $mam_global_fix_this_more_link;
    $mam_global_fix_this_more_link = "<a href='http://nomore.com' >My New Text</a>"; ?>
    <?php the_content( 'Read more ...' ); ?>
    <?php unset($mam_global_fix_this_more_link); ?>

    Be sure to unset the global after the_content so any other loops won't get that same link.

  4. kjeft
    Member
    Posted 1 year ago #

    Thanks so much, it works perfectly!

  5. vtxyzzy
    Member
    Posted 1 year ago #

    You are welcome!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags