• I am a recent convert to WordPress and have been furiously working on my website the past few days. So far I’m loving it but I’m run into a minor snag. Rather than displaying the entire post on the first page, I discovered I could add <!–more–> into the HTML and only display part. however, once someone clicks on “Read more” the subsequent page scrolls down. The codex said to include the following in functions.php which I’ve tried, but the page still scrolls.

    function remove_more_link_scroll( $link ) {
    	$link = preg_replace( '|#more-[0-9]+|', '', $link );
    	return $link;
    }
    add_filter( 'the_content_more_link', 'remove_more_link_scroll' );

    I’m assuming the theme I’m using is somehow interfering but have no way to figure out exactly what is going on.

    The website is at https://www.stepstopassiveincome.com.

    Thank you for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • the ‘read more’ seems to be hard coded – try if you can find it in index.php (?)

    or for the same effect, try to add a filter to functions.php of your theme, to remove the anchor in the single post:

    add_filter('the_content','remove_more_tag_jump_in_single_post');
    function  remove_more_tag_jump_in_single_post( $text ) {
    if( is_single() ) $text = preg_replace( '|<span id="more-[0-9]+"></span>|', '', $text );
    return $text;
    }

    (untested)

    Thread Starter KentyMac

    (@kentymac)

    Thanks for the advice. I couldn’t find ‘read more’ in index.php but did track it down in page.php.

    <?php global $theme; ?>
    
        <div <?php post_class('post clearfix'); ?> id="post-<?php the_ID(); ?>">
    
            <?php
                if(has_post_thumbnail())  {
                    ?><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(
                        array($theme->get_option('featured_image_width'), $theme->get_option('featured_image_height')),
                        array("class" => $theme->get_option('featured_image_position') . " featured_image")
                    ); ?></a><?php
                }
            ?>
    
            <h2 class="title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
            <div class="postmeta-primary">
    
                <span class="meta_date"><?php echo get_the_date(); ?></span>
               &nbsp;  <span class="meta_categories"><?php the_category(', '); ?></span>
    
            </div>
    
            <div class="entry clearfix">
    
                <?php
                    the_content('');
                ?>
    
            </div>
    
            <?php if($theme->display('read_more')) { ?>
            <div class="readmore">
                <a href="<?php the_permalink(); ?>#more-<?php the_ID(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php $theme->option('read_more'); ?></a>
            </div>
            <?php } ?>
    
        </div><!-- Post ID <?php the_ID(); ?> -->

    Could you please help me figure out how to alter this code so that it simply opens the page rather than scrolling down?

    Thank you!

    Thread Starter KentyMac

    (@kentymac)

    Er, actually the above code is in post.php. Apologies.

    change this line:

    <a href="<?php the_permalink(); ?>#more-<?php the_ID(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php $theme->option('read_more'); ?></a>

    to:

    <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'themater' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php $theme->option('read_more'); ?></a>

    basically, remove the anchor part of the link:
    #more-<?php the_ID(); ?>

    Thread Starter KentyMac

    (@kentymac)

    Thank you so much, that worked great!

    One last newbie question, if you don’t mind: How can I do this in a child theme so it will continue to work after updates?

    Thanks again!

    you would need to create a copy of post.php in the child theme, and edit it there.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Removing Page Scroll after More Link’ is closed to new replies.