Page scroll to id for WordPress
Knowledge Base – FAQ
-
No, the plugin works strictly on document's root element (html/body) in order to function properly with element highlighting, deep-linking etc.
-
A quick way is to enable Keep the current element highlighted until the next one comes into view option
Alternatively, you could use the wrapper target shortcode to create your id targets and have full control over the scrolling distance your link(s) stay highlighted.
-
Make sure your target element is at the top by checking its position via browser's developer tools (in most browser's, you can right-click the element and select "Inspect" to view it within the HTML code).
If your link's URL is#top
and no such target id exist in your page, the plugin will scroll the page automatically to the very top (determined by the position of thebody
tag in the HTML). -
The page should scroll to the top (i.e. starting) position of the target, so firstly make sure that your target(s) position is indeed correct (or what you want it to be). Note that the top position of elements does not include CSS margins, so check if you need to adjust any of your target's CSS properties.
In general, you can adjust/tweak the scroll-to position by changing your target(s) position or by using plugin's "Offset" option.
For example, if your page has a top sticky/fixed-positioned menu, you should set an offset value in order to avoid the menu covering your content when the page is scrolled. -
Add the full address as your links URL/href value instead of just the hash with the id. For example, instead of
#my-id
, usehttp://my-site.com/page/#my-id
or/page/#my-id
etc. in the link's URL. -
The plugin has the options to scroll from/to different pages enabled by default (if not, enable it), so you only need create links with the full address in their URL (e.g.
http://my-site.com/page/#my-id
). -
You should use plugin's "Offset" option and set how much you want to offset page scroll (see option for more info).
-
Yes, via Disable plugin below option. You can set a
width
orwidth,height
value (indicating pixels) below which the plugin will be disabled (see option for more info). -
It does. You can take a look at the jQuery/non-wordpress version of the plugin for available options, methods etc. The plugin script offers things like changing options on-the-fly, triggering scroll events programmatically, running callback functions at the beginning and end of each scroll etc., so contact me if you need help 🙂
-
Yes, set different vertical and horizontal offsets by adding comma separated values in plugin's "Offset" option field.
For instance, inserting100,50
will offset vertical scrolling by 100 pixels and horizontal scrolling by 50 pixels). -
Yes. If you're using plugin's "Insert/edit Page scroll to id link" button in WordPress visual editor, you can set a link-specific offset value in the "Offset" field of the "Page scroll to id" modal.
If you're using plugin's shortcode, you can use the offset attribute like so:
[ps2id url='#some-id' offset='100']link text[/ps2id]
If you create your links manually in HTML, you can use the
data-ps2id-offset
attribute like so:<a href="#some-id" rel="m_PageScroll2id" data-ps2id-offset="100">link text</a>
For WordPress menu items, you can use the class
ps2id-offset-NUMBER
in the menu item Classes field, replacingNUMBER
with the offset you want for that specific menu link. For example, for 80px offset, add the classps2id-offset-80
(feature added in plugin's version 1.7.4). -
Firstly, you need to determine if highlighting comes from "Page scroll to id" or by your WordPress theme. If you didn't use any of the plugin's highlight classes in your CSS, then the highlighting you see comes from your theme's stylesheet. It's common for themes to style current page menu items differently. If that's the case, you should edit (or overwrite) your theme's CSS.
If you did use plugin's
mPS2id-highlight
class in your CSS, then you can try any of the following:- Enable Allow only one highlighted element at a time option in plugin settings.
- Instead of
.mPS2id-highlight
, use.mPS2id-highlight-first
or.mPS2id-highlight-last
selectors in your CSS to style the first or last highlighted link accordingly.
-
- Create your menu items/links on your menu (Appearance → Menus). You should create/add "Custom links" as these type of links allow us to enter a custom URL with the id we want. Your links URL could be in the form of
#my-id
,http://my-site.com/page/#my-id
,/page/#my-id
etc. - Create the id targets that your links will scroll to, using plugin's "Insert Page scroll to id target" button in WordPress visual editor or plugin's shortcodes.
Another option is to use id values that already exist in your theme. - The plugin is enabled by default on WordPress Menu links so normally everything should work.
Some themes have their own custom function for generating menus which might prevent the "Enable on WordPress Menu links" option from working. In such case or if for any reason you need to enable the plugin on your links manually, do the following:- Go to Appearance → Menus to edit your links.
- Click "Screen Options" at the very top and make sure "CSS Classes" is checked.
- Click to edit each one of the links you've created and insert the
ps2id
value in "CSS Classes" field. - Save your menu. Any menu item/link with
ps2id
class will be handled by the plugin.
.menu-item a[href*='#']
, so try adding this value in "Selector(s)".
- Create your menu items/links on your menu (Appearance → Menus). You should create/add "Custom links" as these type of links allow us to enter a custom URL with the id we want. Your links URL could be in the form of
-
You basically need to see the generated HTML code of your page(s) and search for
id="some-id"
patterns, e.g.<div id="some-id">...</div>
The best way to do this is to use browser's developer tools (Chrome and Firefox are browsers with great developer tools), so the steps are as follows:- Open your page in say Google Chrome.
- Hit the F12 key or right-click any element a click "Inspect" to open the developer tools window.
- Switch to "Elements" panel (if necessary) where you can see the page's HTML code (in real-time).
In this panel you can toggle each HTML tag and hovering over each one, highlights it in browser's main window (where you can conveniently see its actual position within the page/document). The tags/elements you should look for are within thebody
tag.
You can also right-click any element in the main window (e.g. a title, paragraph, section, image etc.) and click "Inspect" to highlight it in the "Elements" panel. There you can see if the inspected element has an id attribute value and use it as your link(s) target.
-
It is possible only if you can add custom javascript in your template/theme. See "Page scroll to id with mousewheel and keyboard" guide.
-
You can change the scroll duration/speed of a link by giving it a special class in the form of
ps2id-speed-VALUE
(i.e.ps2id-speed-600
) withVALUE
indicating the scroll duration in milliseconds (lower duration equals faster scrolling).If you're using plugin's "Insert/edit Page scroll to id link" button in WordPress visual editor, you can add the special class in the "Custom class(es)" field of the "Page scroll to id" modal.
If you're using plugin's shortcode, you can use the class attribute
-
Yes. Add
define('PS2ID_MINIFIED_JS', false);
in yourwp-config.php
file to instruct the plugin to load the non-minified/development version of its scripts. -
Image map links (
area
elements) work the same as normal links (anchors). See this comment and this thread. -
Some themes and plugins change document's length while the page is scrolling. A common example would be when a menu becomes sticky (i.e. fixed) only when the user has scrolled down the page. There are cases where when this happens, the menu's previous state (when it was not sticky) space becomes zero, thus changing the document/page length. This means that targets position is different according to the state of the menu, that's why when clicking the link a second time, scrolling seem to become "correct".
You can deal with this either by adjusting your menu CSS (not always possible) or by enabling Verify target position and readjust scrolling (if necessary), after scrolling animation is complete option in plugin's settings.
-
You can overwrite some of plugin's option via javascript. For example, you could add the following script in your theme's header.php inside the head tag:
window.ps2id_special_params={ highlightSelector: "a.some-class" };
You can use the following option parameters:
highlightSelector
,scrollEasing
,scrollSpeed
,keepHighlightUntilNext
,forceSingleHighlight
,appendHash
,layout
,offset
You can also do the same by adding the following in your theme/child-theme functions.php:
add_action( 'wp_enqueue_scripts', 'ps2id_special_params_0', 1 ); function ps2id_special_params_0(){ if(class_exists('malihuPageScroll2id')){ $pages_arr = ps2id_mw_get_pages(); if(is_single( 23 )) : wp_register_script( 'page-scroll-to-id-special-js-params', '', array(), '0.0.1', false ); wp_enqueue_script( 'page-scroll-to-id-special-js-params' ); wp_add_inline_script( 'page-scroll-to-id-special-js-params', 'window.ps2id_special_params={ highlightSelector: "", scrollEasing: "easeOutCirc", scrollSpeed: 700, keepHighlightUntilNext: false, forceSingleHighlight: false, appendHash: false, layout: "auto", offset: 100 };'); endif; } }
The function above will add the script on the post with id 23 (see:
is_single( 23 )
). -
In plugin settings change the "Selecotr(s)" option value from
a[href*=#]:not([href=#]):not([data-vc-tabs]):not([data-vc-accordion])
to the defaulta[href*='#']:not([href='#'])
The issue is related to this topic.
Pages: 1 2
Hello, I have an issue, an error screenshot (https://prnt.sc/xk1t47MBdl6E).
The cause screenshot (https://prnt.sc/7BhE9ZqaXfWU).
Explanation: the parameter should be a string, but an array is given.
Could you fix it, please?
Hi,
This is a known issue which is already fixed in plugin’s development version (see link below) and will be fixed in the next plugin version (1.7.8).
https://downloads.wordpress.org/plugin/page-scroll-to-id.zip
If you don’t want to wait for the next version release, you can use the development version and update to version 1.7.8 when it becomes available (as you normally do).
Hi,
i have a small issue. on the main page the plugin works perfectly.
But when i am on a sub page like https://endlesscity-records.com/artists/
and i click on the menu any links (except: home & sub-menus)
it does not jump back to the main page.
i am using costume links with #myanchhorID in the menu
cause if i use the full link (like https://endlesscity-records.com/#myanchhorID), the mainpage doesnt scroll, it first reloads the complete page, and then scrolls from the top to the anchor point.
any idea?
Regards,
Simon
Hi Simon,
It seems there is another script affecting the links with absolute URLs like
https://endlesscity-records.com/#some-id
(this script may be part of the theme).Try to use the root-relative URL in your links, meaning that instead of
https://endlesscity-records.com/
, start with a simple/
which defines the domain root.For example, change your “Releases” link URL to:
/#releases
and it’ll work from any page.
You can do this for any page, like
/events-list/#some-id-in-events
,/#some-id-in-home
etc.AMAZING! Works like a charm!
Thank you soo much.
Just sent you a Donation to get a Coffee!!! 😉
Regards
Simon
Thank you! Glad I helped 🙂
I had been using the page-scroll-to-id plugin on my website without any problems.
My website went down and when I contacted BlueHost, they said my page-scroll-to-id plugin was casuing a conflict and needed to be disabled.
Any suggestions on if/how I can reactivate this plugin without crashing my BlueHost hosted website?
Thanks for any suggestions.
Hi,
I’ve never got any issues with BlueHost (or any other hosting tbh).
You need to ask them or find what the error was.
Also if you changed something before your site went down.
Does reactivating the plugin cause the site to go down? If yes, what error do you get? Is PHP debug enabled?
I can not reactivate it, when I try I get the following error message:
We were unable to switch the status of Page scroll to id. Please try again.
Could there be a conflict becasue I am also using BeTheme?
I had been usingJetPack to monitor my site usage right before my site crashed.
Could the conflict be realted to JetPack?
Can’t say for sure (I’ll try making some tests).
Can you try the following?
Firstly, delete “Page scroll to id” in wp admin plugins page.
Download plugin’s development version:
https://downloads.wordpress.org/plugin/page-scroll-to-id.zip
Upload and activate it.
Let me know if it works.
Thanks for the suggestion.
I think the problem is a conflict with BeTheme.
I will have to figure out another solution.
Thanks.
Same on my website, if I updatet to PHP 8.0. I solved problem same way.
updating to version 1.7.7 caused an error – so there is a bug on your update.
I downloaded and replaced it with the previous version 1.7.6 – and it solved the problem.