This website uses cookies to personalise ads and to analyse traffic ok
web design

Page scroll to id for WordPress

Page scroll to id is a fully featured WordPress plugin for creating links that scroll the page smoothly to any id within the document. The plugin replaces browser’s “jumping” behavior with a smooth scrolling animation, when links with href value containing # are clicked.
It provides all the basic tools and advanced functionality for single-page websites, in-page navigation, back-to-top links etc. with features like: adjustable scrolling animation duration and easing, link and target highlighting via ready-to-use CSS classes, vertical and/or horizontal scrolling, scrolling from/to different pages etc.

Get started

The plugin works by “connecting” links with href/URL in the form of #my-id or to sections/elements within the document with an equivalent id attribute value (e.g. <div id="my-id">...</div>). Clicking such links will scroll the page smoothly to their target id position.

Get started by creating or setting-up your links. The plugin is enabled by default on WordPress Menu links (created in Appearance → Menus), so you can start adding custom links and set their URL to the id/target you want to scroll to (e.g. #my-id, /page/#my-id, etc.).
You can use id values that already exist in your theme or you can create your own id targets using plugin’s “Insert Page scroll to id target” button in wp post visual editor or the [ps2id] shortcode (e.g. [ps2id id='my-id'/]).

To create links within your content, use plugin’s “Insert/edit Page scroll to id link” button and/or shortcode (e.g. [ps2id url='#my-id']link text[/ps2id]) in wp post visual/text editor.
To enable the plugin on existing links, add the ps2id class or the m_PageScroll2id rel attribute to them, making sure the link’s href/URL value contains a hash (#) with the id of the section you want to scroll-to. In addition, you can simply add your links CSS selector (e.g. .menu-item a, a[href*=#]:not([href=#]) etc.) in “Selector(s)” field in plugin settings.

To highlight your links (or targets), use the classes provided by the plugin in your theme’s stylesheet or custom CSS. The default highlight class is mPS2id-highlight but you can set your own in the “Classes & highlight options”. For example, to style the highlighted link (the link whose target element is considered to be within the viewport), you could add in your CSS:
a.mPS2id-highlight{ background: #ff0; } or .menu-item a.mPS2id-highlight{ background: #ff0; } for highlighting custom menus links only.

If you have a fixed-positioned/sticky menu which overlaps your target’s content when page scrolling is completed, insert your menu CSS selector or a fixed pixel value in the “Offset” field. For example, inserting #navigation-menu will offset the scroll-to position according to the height/width/position of the element with id navigation-menu. In the same manner, setting the “Offset” value to 100 will offset page scrolling by 100 pixels.

Plugin settings


Use the Selector(s) field when you need to instruct the plugin to handle specific links. The value(s) should be anchor tags (a, i.e. links) in the form of strings that represent ways of choosing elements in the DOM (i.e. CSS selectors).
Each selector is separated by comma, so multiple selectors can be defined as: selector1, selector2, selector3 etc.

The default selector value is a[rel='m_PageScroll2id'], meaning the plugin handles by default all anchor elements (a) with m_PageScroll2id rel attribute value.
Other selector examples could be: a[href*='#'] (links that contain # in their href/URL attribute), a[href='#my-id'] (links with href attribute value: #my-id), a.className (links with class: className).

To enable the plugin on any link that has a hash (#) in its URL, insert a[href*=#]:not([href=#]) as a single selector.

Other default selectors which the plugin is applied automatically include the class ps2id (actual selectors: .ps2id > a[href*='#'] and a.ps2id[href*='#']). This means that any link with a hash in its URL/href (e.g. #my-id) which has the class or is contained (direct children) within an element with the class ps2id will be handled by the plugin automatically.

The option “Enable on WordPress Menu links” (enabled by default) enables the plugin automatically on custom links created in WordPress Menus.

Scroll duration

Scroll animation duration (i.e. scrolling speed) in milliseconds (1000 milliseconds equal 1 second). Lower values equal faster scrolling.

“Auto-adjust scrolling duration” option (enabled by default) lets the plugin fine-tune scrolling duration/speed according to target and page scroll position. This normalizes the animation duration in order to avoid short-distance scrolling taking too long (e.g. a page scroll of just 100 pixels will last shorter than the value specified in “Scroll duration”).

Scroll type/easing

Scroll animation easing type (i.e. the way the animation progresses at different points within its duration).
You can set different easing types according to page scrolling state: one that is applied when the page is idle (no scrolling currently running) and another that applies while page is scrolling (when a link is clicked while the page is animated/scrolling).

Scroll duration and easing demo

Scroll behavior

Always scroll smoothly when reaching the end of the page/document option adjusts scroll-to position so it does not exceed document length. For example, when scrolling to a target element that is at the bottom of the page, the scrolling animation stops smoothly at bottom of the page instead of “breaking” at an earlier point.
Enable Stop page scrolling on mouse-wheel or touch-swipe option if you want to stop page scrolling when the user tries to scroll the page manually (e.g. via mouse-wheel or touch-swipe).

Page layout

Set page scrolling direction (i.e. restrict scrolling) to top-bottom (vertical) or left-right (horizontal) accordingly. For both vertical and horizontal scrolling select auto.
This option does not transform your theme’s templates layout (i.e. it won’t change your theme/page design from vertical to horizontal).


Offset scroll-to position by x amount of pixels or by selector. The offset value can a be a positive or negative number (indicating pixels), or a matching set of elements in your html (selector). For example, setting the value to 50 will stop page scrolling 50 pixels before reaching the target.
If you need to offset scrolling according to the height (or width) of some element (e.g. according to a responsive/sticky navigation menu), insert the element’s selector in the Offset field. For example, if you have a top fixed/sticky menu with id navigation-menu, set the offset value to #navigation-menu in order to stop page scrolling below it and avoid the menu overlapping your content.

To set different vertical and horizontal offsets (e.g. when Layout is set to auto), add comma separated values in Offset field, e.g. 100,50 (vertical offset 100 pixels, horizontal offset 50 pixels).

The plugin offers selector expressions in order to define more advanced offset values. Examples:

  • :fixed expression – Offset by element with id “some-id” and CSS position fixed: #some-id:fixed
    Assuming vertical layout, the value above will offset scrolling according to the height of #some-id element (i.e. the element that has id some-id), but only when this element CSS position is fixed (i.e. element is sticky). This is useful when for example you have a navigation menu that is sticky/fixed only above a specific viewport size (e.g. only on desktop).
  • :height() expression – Offset by element with class “some-class” and height equal to 100 pixels: .some-class:height(100)
    The value above will offset scrolling according to the height (on vertical layout) of .some-class element (i.e. the element that has class some-class), but only when this element height is exactly 100 pixels.
  • :width() expression – Offset by element with id “some-id” and width greater than 800 pixels: #some-id:width(>800)
    The value above will offset scrolling according to the height of #some-id element, but only when this element width is greater than 800 pixels. This is useful when having responsive navigation menus. For instance, you might have a responsive top sticky menu that switches to a “hamburger” menu when viewport is 800 pixels wide or less. Assuming the menu is as wide as the page/viewport, you’d only want to apply its height as offset when its width is greater than 800 pixels (i.e. when it’s not “hamburger” menu). Adding: #your-menu-id:width(>800) as the offset value will do exactly that.
  • Multiple expressions – Offset by element with id “some-id”, CSS position fixed and height between 50 and 100 pixels: #some-id:fixed:height(>50):height(<100)
    The value above will offset scrolling according to the height of #some-id element, but only when this element CSS position is fixed and its height is anywhere between 51 and 99 pixels.

Highlight selector(s)

The matching set of elements (i.e. selectors) handled by the plugin, that will be eligible for highlighting. The value(s) should be anchor tags (a, i.e. links).

The plugin highlights by default all the links it handles. Using this field, you can specify which links should be highlighted and exclude the rest.
For example, assuming you have various links that scroll the page (e.g. menu links, back-to-top etc.) and you want only the menu links to get highlighted, you could insert:
.menu-item a[href*='#']

Classes & highlight options

The plugin adds special classes to the links and the target elements it handles when the following happen:

  • When a link is clicked, it gets the mPS2id-clicked class.
    You can change this class name to your own and you can use it in your CSS to style the clicked link. For instance:
    .mPS2id-clicked{ background: #ff0; }
  • When a link’s target element is within the viewport (i.e. visible on the screen), the link gets the mPS2id-highlight class and the target element gets the mPS2id-target class.
    You can change these class names to your own and you can use them in your CSS to style the highlighted link and target. For instance:
    .mPS2id-target{ background: #ff0; }
    a.mPS2id-highlight{ background: #ff0; }

In addition, the plugin will add the above highlight classes with the -first and -last suffix (e.g. mPS2id-highlight-first, mPS2id-highlight-last) in order to differentiate multiple highlighted elements. This is useful when you need to style only the first or last of the highlighted links or targets in your CSS.
For example, if multiple links are highlighted at the same time, instead of using .mPS2id-highlight in your stylesheet, you could do:
a.mPS2id-highlight-first{ background: #ff0; }

An alternative way of restricting highlight to a single link/target and prevent multiple elements from being highlighted at the same time, is to enable Allow only one highlighted element at a time.

There are times when you need to keep at least one element (e.g. a menu link) always highlighted. Enable Keep the current element highlighted until the next one comes into view option if you need such functionality/behavior and your template/page is laid out in a way that at certain scrolling points there are no target sections visible on the screen (no links highlighted).

Enable Highlight by next target option when your target elements have zero height/width to improve highlighting behavior. This option is useful when you add id targets in your content via plugin’s buttons or the [ps2id id='some-id'/] shortcode, as it extends the scrolling range at which an element stays highlighted.

Disable plugin below

Set the viewport/screen-size in pixels, below which the plugin will be disabled. The value can be width or width,height.
For example, insert 1024 to disable plugin’s functionality when the viewport/window width is 1024 pixels or less. Insert 1024,600 to disable plugin when viewport width is 1024 pixels or less and viewport height is 600 pixels or less.
Please note that the values entered will match CSS media queries.

Leaving the field value empty or 0 (default) disables the option.


Check Display widgets id attribute in order to show the id attribute of each widget in Appearance → Widgets. This is a convenient way of finding existing id values in order to use them as links targets.
You can also create your own id targets in widgets via the “Page scroll to id target” widget.

Enable insert link/target buttons in post visual editor activates plugin’s buttons in WordPress visual editor toolbar. You can use these buttons to insert links and id targets in your content.

Advanced options

If another plugin or a theme script handles page scrolling and conflicts with “Page scroll to id”, try enabling Prevent other scripts from handling plugin’s links option. This option attempts to remove (on-the-fly) javascript click events by other scripts from the links. Please note that this might not work on some themes or plugins, as it depends on the way those scripts are attaching the link events.

Enable Normalize anchor-point targets to normalize/reset the CSS properties (height, line-height, border etc.) of anchor-point targets.

wp-config options

define('PS2ID_MINIFIED_JS', false);
Use the PS2ID_MINIFIED_JS constant (permanent global variable) in wp-config.php to select which script files will be loaded on the front-end by the plugin. Adding the above in wp-config.php instructs the plugin to load the non-minified/development version of its scripts.

Divi WordPress Theme Monarch Social Sharing Plugin

Plugin shortcodes

Plugin’s [ps2id] shortcode can be inserted directly in WordPress post editor (as with any WordPress shortcode) in order to create links and id targets in your content.

[ps2id url='#some-id']link text[/ps2id]


  • url (required) – Link URL
    [ps2id url='#some-id']link text[/ps2id]
    [ps2id url='']link text[/ps2id]
    [ps2id url='/page/#some-id']link text[/ps2id]
  • offset (optional) – Link-specific offset (bypasses the general offset value in plugin settings)
    Offset scrolling by 100 pixels
    [ps2id url='#some-id' offset='100']link text[/ps2id]
    Offset scrolling by the height (or width for horizontal layout) of the element with id navigation-menu
    [ps2id url='#some-id' offset='#navigation-menu']link text[/ps2id]
    Offset vertical scrolling by 100 pixels and horizontal scrolling by 50 pixels
    [ps2id url='#some-id' offset='{"y":"100","x":"50"}']link text[/ps2id]
  • class (optional) – Link custom class(es)
    You can give the link one or more custom classes (separate multiple classes with space).
    [ps2id url='#some-id' class='class-a']link text[/ps2id]
    [ps2id url='#some-id' class='class-a class-b']link text[/ps2id]

    You can change the scroll duration/speed of the link (bypass the general scroll duration value in plugin settings) by adding a special class in the form of ps2id-speed-VALUE (i.e. ps2id-speed-600) with VALUE indicating the scroll duration in milliseconds (lower duration equals faster scrolling).

    [ps2id url='#some-id' class='ps2id-speed-400']link text[/ps2id]
    [ps2id url='#some-id' class='ps2id-speed-1300 class-a class-b']link text[/ps2id]

Target id shortcode

There are 2 target shortcodes:

1. Anchor-point target

[ps2id id='some-id'/]

2. Wrapper target

[ps2id_wrap id='some-id']
your content...

You can use the wrapper target ([ps2id_wrap]) when you need to wrap content in a target id (same as adding an id attribute to some content). Doing this gives you better control over the highlighting of associated links.
In addition, wrapper target allows you to include other shortcodes within its content, e.g.

[ps2id_wrap id='some-id']
content... [ps2id url='#another-id']link text[/ps2id] 
more content...
[ps2id id='another-id'/]


  • id (required) – Target id
    [ps2id id='some-id'/]
    [ps2id_wrap id='some-id'] your content... [/ps2id_wrap]
  • target (optional) – The element that’ll be considered as the actual target for highlighting
    This can be useful when you need better highlighting for target elements that have zero dimensions.
    The associated link will scroll to #some-id element but will be highlighted as if its target is the next adjacent div (the div immediately following #some-id element)
    [ps2id id='some-id' target='#some-id + div'/]
    The associated link will scroll to #some-id element but will be highlighted according to #another-id element
    [ps2id id='some-id' target='#another-id'/]

Previous versions

Pages: 1 2


Post a comment
  1. aidan
    Posted on April 16, 2017 at 22:58 Permalink

    First of all, thank you. Great plugin. Works awesomely:)

    I wonder if this plugin (or another one) would be able to do the following:

    I would like when my users scrolled down, on keypad or mouse, that my site would smooth scroll to my next row (container) automatically?

    I have seen some sites do this. Sorry I can’t get an example right now.

    Many thanks,


  2. Muslima
    Posted on April 13, 2017 at 18:02 Permalink

    When you click on the menu item, it will scroll, but the pressed item doesn’t change color to the hovering color. Can you say what should I do?
    You can see my site there

    • malihu
      Posted on April 13, 2017 at 18:19 Permalink


      Use plugin’s highlight class(es) in your CSS to style the link:

      #menu-main > li > a.mPS2id-highlight { /* the styling you want */ }

      • Muslima
        Posted on April 14, 2017 at 14:03 Permalink

        I opened style.css in Editor and put this:

        #menu-main li a.mPS2id-highlight {

        But it doesn’t work


        • malihu
          Posted on April 14, 2017 at 18:04 Permalink

          What do you mean not working?
          It works for me (on your first 2 menu links). I see the link color changing to blue as I scroll into its section.

  3. Sabine
    Posted on April 4, 2017 at 18:02 Permalink

    Thanks for your great plugin, it’s the only one that seems to work at all for me, except for one thing: the smooth scrolling only works once. If I click a second link from the menu, it jumps instead of scrolling. Are you able to help me with this? It’s the website in the comment URL.
    Thanks a lot!

    • malihu
      Posted on April 4, 2017 at 21:16 Permalink


      The plugin works only on links (<a /> tags) with a valid href attribute value. Your menu is a non-link, dropdown menu (<select /> tag) which jumps to page sections via custom javascript code set by its developer.

      In order to make “Page scroll to id” work with your select menu you’d need to unbind its javascript and create a custom script which will use plugin’s scrollTo method within a jQuery change event (.change()). In short, it’d need custom js work.

      The smooth scrolling seems to be working on the first selection because it goes to a different page/URL and the plugin is able to scroll the page when it first loads as it takes the target value (#id) from the URL itself.

      • Sabine
        Posted on April 6, 2017 at 14:03 Permalink

        Thanks a lot for your great explanation! With this information I can go on! Also a thousand thanks for being that fast!!!

  4. Olga
    Posted on March 28, 2017 at 23:59 Permalink

    I’ve installed and activated Page Scroll To ID plugin, but 2 “scroll to id” icons aren’t showing in my editor.
    How can I fix this?

    • malihu
      Posted on March 29, 2017 at 07:53 Permalink


      Do you use SiteOrigin page builder or something similar? Their widgets don’t allow custom buttons/icons in the editor.

      Maybe you can use plugin’s shortcodes or plain HTML to create your targets and/or links like described in plugin’s tutorial(?)

  5. my
    Posted on March 27, 2017 at 11:47 Permalink

    Your plugin is awesome and often work without problem. But on this site that i am working on for a client seems to jump after smooth scroll. And in safari it glitches?

    Thanks for your time!

    • malihu
      Posted on March 27, 2017 at 12:43 Permalink


      The site in question is the one you added in the comment URL correct?

      I checked it and the issues your having come from another script (...themes/kalium/assets/js/joinable.min.js) which handles the links and page scrolling while preventing “Page scroll to id” from doing its thing.

      Go to “Page scroll to id” settings and enable “Prevent other scripts from handling plugin’s links” option. This should fix the problem(s).

      Let me know

  6. Diyan
    Posted on March 24, 2017 at 14:38 Permalink

    Hi, I like the ease of use of this plugin.

    I wonder if there is a way to trigger a different offset value on mobile devices? Best case scenario would be: being able to set the trigger point (in px) too.


    • Diyan
      Posted on March 24, 2017 at 14:40 Permalink

      oh my, I should have read the comments first! sry for bothering you.

  7. Olivia
    Posted on March 21, 2017 at 03:36 Permalink

    I add the id into each page, and then create a custom link to add to the menu – and i made sure that i have “scroll to/from” different pages highlighted – and i still cannot get it to scroll smoothly throughout the website from page to page.

    • malihu
      Posted on March 23, 2017 at 01:26 Permalink

      Please post a link with the problematic page so I can check it and help. Also make sure your links URL matches exactly the URL you see in browser’s address bar (e.g. https vs http, if www part is required etc.).

  8. Carmen
    Posted on March 11, 2017 at 23:48 Permalink

    Hi, I´ve been using your Scroll to Id plugin for around a year and it works great, thank you!

    My only question is… I have a fixed to top navigation and I am using 90px offset which is perfect for desktop. Since I don´t have a fixed top navigation for mobile, I would like to know if I can reduce to half (45px) of the offset pixels only on mobile, maybe through a guery?

    • malihu
      Posted on March 12, 2017 at 01:02 Permalink


      You can’t use a query for a fixed offset value (e.g. 90 pixels).

      What you can do, is use the offset expressions on a non-fixed selector-based offset value.

      These expressions restrict offset to certain conditions like only when the element is fixed, when the element is above a specific width etc.
      For example in your case, you could set the offset to be the height of your logo image but only when the top menu is sticky/fixed:

      nav.sticky:fixed .logo > img

      Insert the above value in plugin’s “Offset” (instead of 90) and test if it works in your layout.

  9. Curtis
    Posted on March 9, 2017 at 18:38 Permalink

    The plugin is working great with just one glitch. The last item on my menu and page is Contact. It won’t highlight. Suggestions?

    Thank you!!

    • malihu
      Posted on March 9, 2017 at 19:33 Permalink


      You have both “Highlight by next target” and “Allow only one highlighted element at a time” options enabled. Try disabling “Highlight by next target”.

  10. Roman
    Posted on March 2, 2017 at 22:06 Permalink

    Hi , “Is “Enable insert link/target buttons in post visual editor” option checked?”
    there is no problem!
    On my website 4 plugin: Easy Modal ,Contact Form 7 , Page Builder, TineMCE . if they could affect the operation of your plugin?
    Tried in different modes editor button in which there is no (

  11. Roman
    Posted on March 2, 2017 at 20:20 Permalink

    Hey, help me please. I installed your plugin “page scroll to id”, but it does not work ((no button “Insert Page scroll to id targe” in a text editor. Tell me how to fix it?

    • malihu
      Posted on March 2, 2017 at 20:36 Permalink

      It’s impossible for me to know what happens and help without access to your site or additional info.

      Is “Enable insert link/target buttons in post visual editor” option checked?
      Do you use other plugins that may affect post/page editor toolbar?
      Is your editor switched to “text” or “visual”?
      What editor does your theme use (standard, custom etc.)?

      • Roman
        Posted on March 2, 2017 at 22:07 Permalink

        Hi , “Is “Enable insert link/target buttons in post visual editor” option checked?”
        there is no problem!
        On my website 4 plugin: Easy Modal ,Contact Form 7 , Page Builder, TineMCE . if they could affect the operation of your plugin?
        Tried in different modes editor button in which there is no (

        • malihu
          Posted on March 3, 2017 at 16:02 Permalink

          Ah yes. “Page builder” removes most 3rd party plugin buttons from its widget editor. That’s why you don’t see them.

          Instead of the buttons, you can use plugin’s shortcodes. The shortcodes have the same functionality as the buttons but you have to add them manually as text.

          FYI I’ll try to contact the “SiteOrigin” guys and ask them to allow “Page scroll to id” buttons in their editor.


Post a comment

Your e-mail is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
You can write or copy/paste code directly in your comment using the <code> tag:
<code>code here...</code>
You may also use the data-lang attribute to determine the code language like so:
<code data-lang-html>, <code data-lang-css>, <code data-lang-js> and <code data-lang-php>