- This topic has 7 replies, 2 voices, and was last updated 8 years, 10 months ago by
Tom.
-
AuthorPosts
-
April 11, 2016 at 2:57 am #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
TonyApril 11, 2016 at 8:31 am #185940Tom
Lead DeveloperLead DeveloperHi 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 🙂
April 11, 2016 at 10:27 am #185990Tony
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?April 11, 2016 at 9:55 pm #186071Tom
Lead DeveloperLead DeveloperThe 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.
April 12, 2016 at 2:55 am #186137Tony
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–>April 12, 2016 at 10:44 pm #186382Tom
Lead DeveloperLead DeveloperYou 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.
April 13, 2016 at 8:47 am #186535Tony
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.
April 13, 2016 at 11:10 pm #186679Tom
Lead DeveloperLead DeveloperHmm, 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/
-
This reply was modified 8 years, 10 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.