1

I'm creating a theme, and I want to prevent the page from being scrolled when a user clicks 'Read More' and the code given in the Wordpress Codex is not helping me at all.

My functions.php is exactly the same as the snippet in the Codex and the relevant line of my index.php is:

<div class="content"><p><?php the_content(__('Read More')); ?></p></div>

Edit: I have a new, weird bug: the content of the Codex snippet is being shown as raw HTML in my blog and admin pages.

4
  • 1
    Can you clarify what you mean by "scrolled"?
    – kraftner
    Commented Apr 4, 2014 at 13:53
  • I mean that the link, when clicked, leads to a position some way down the page instead of at the top. Commented Apr 4, 2014 at 13:57
  • There is a theme or a plugin involved in this somehow. I assume it is loading Javascript or creating links with #someid. Without knowing the details there is no way to answer though.
    – s_ha_dum
    Commented Apr 4, 2014 at 13:58
  • I'm using the WordPress Popular Posts and WP-PageNavi plugins. No js in the theme itself, which I created from scratch. Commented Apr 4, 2014 at 14:08

1 Answer 1

0

There is an explanation in the WordPress Codex which I copy here for reference.

Don't forget <?php and ?>

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

Prevent Page Scroll When Clicking the More Link

4
  • this isn't working for me, as I mentioned in the question itself Commented Apr 4, 2014 at 14:12
  • You do have <?php and ?> in there?
    – kraftner
    Commented Apr 4, 2014 at 14:17
  • I feel really stupid now. Commented Apr 4, 2014 at 14:21
  • I won't tell anybody ;)
    – kraftner
    Commented Apr 4, 2014 at 14:22

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.