Prevent Page Scroll When Clicking the More Link

Home Forums Support Prevent Page Scroll When Clicking the More Link

Home Forums Support Prevent Page Scroll When Clicking the More Link

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #185884
    Tony

    Hi Tom
    By default, clicking the .more-link anchor opens the web document and scrolls the page to section of the document containing the named anchor.
    I have read that it is possible to prevent this scrolling function.

    Can you tell me how to implement this in GP please?

    Cheers
    Tony

    #185940
    Tom
    Lead Developer
    Lead Developer

    Hi Tony,

    You can add this function:

    add_filter( 'generate_more_jump','generate_disable_more_jump' );
    function generate_disable_more_jump()
    {
        return '';
    }

    Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

    That should do it 🙂

    #185990
    Tony

    Not tried yet. Is there a way to make this specific to a post or to re enable scroll on a specific post?
    Ditto on a page?

    #186071
    Tom
    Lead Developer
    Lead Developer

    The more jump functionality only applies to blog posts, not pages. For this reason, and since it only happens on the blog page, I’m not sure if it’s do-able to target specific posts.

    You can try playing with conditionals in there, but it might get a little messy mixing it up like that.

    #186137
    Tony

    It works fine – thank you.
    I’m not sure where I would start with conditional code in the php.

    I’m not sure what elements of a post are available – Category? Tag?

    Could I insert another element when I want it to scroll and then recognise it in the php?
    e.g. <!–more–><!–scroll–>

    #186382
    Tom
    Lead Developer
    Lead Developer

    You could try this:

    add_filter( 'generate_more_jump','generate_disable_more_jump' );
    function generate_disable_more_jump()
    {
        if ( has_tag( 'No Jump) ) :
            return '';
        endif;
    
        return apply_filters( 'generate_more_jump','#more-' . get_the_ID() );
    }

    Basically it should check if you post has the “No Jump” tag, and if so, won’t jump.

    #186535
    Tony

    This fails.
    I’m a bit confused – looking at the if statement it returns the same as it did before if the tag is found? Should the code be:

    if ( has_tag( ‘No Jump’) ) :
    return apply_filters( ‘generate_more_jump’,’#more-‘ . get_the_ID() );
    endif;
    return ‘ ‘;

    BTW is the full stop after #more- correct? I tried a comma but it makes no difference. Also tried removing space after full stop.

    The code recognises the tag but this line of code causes a problem:
    return apply_filters( ‘generate_more_jump’,’#more-‘ . get_the_ID() );

    I have it so the first post on the Home page does have the tag and the second post does NOT have the tag.

    As soon as a post is found NOT to have the tag no further posts are shown on the Home page and the post without the tag only shows the post title.

    There is no scroll when clicking ‘more’ on the first post even though it has the tag which seems correct given the way the if statement is setup.

    I am sure we can get it working – this is not an urgent issue though.

    Is there not a way to detect some text in the post e.g. <!–scroll–> instead of a tag? I don’t use post tags anywhere at this time but may do in the future

    • This reply was modified 8 years, 10 months ago by Tony.
    #186679
    Tom
    Lead Developer
    Lead Developer

    Hmm, it may be that we’re trying to force something that’s not easily achievable.

    The code I provided is correct, periods and all.

    It’s saying this:

    If we have the “No Jump” tag, return nothing (no jump).

    The above didn’t return so we’re still reading, return the regular more tag.

    You may want to ask about creating a new tag like here: http://wordpress.stackexchange.com/

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.