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

Page scroll to id for WordPress tutorial

Basic tutorial for using “Page scroll to id” WordPress plugin on your WordPress site.

In order to use the plugin on your WordPress site (after installing and activating it), you need to do the following:

  1. Create id targets the page will scroll to or find existing id attributes in your theme to use with your links.
  2. Create links that point to those targets or enable the plugin on links that already exist in your site.

Creating id targets

Creating id targets in post visual editor

tinymce-custom-btn-ps2id-target In post visual editor, click the toolbar button “Insert Page scroll to id target” to create a target at the cursor position in the editor.

page-scroll-to-id-target-modal In “Page scroll to id target” modal insert the id value you want (e.g. some-id) and click “OK”. The target shortcode (e.g. [ps2id id='some-id' target=''/]) will appear in the editor. Update/save the post/page. You can now use this id value in your link(s) URL (e.g. #some-id).

Creating id targets in post editor via shortcodes

In post visual or text editor, enter [ps2id id='some-id'/] in the place you want to create the target and set the id attribute to the value you want. This will create a simple anchor-point target. If you want to wrap your content (or part of your content) in a target id (same as adding an id attribute to some content), use the [ps2id_wrap] shortcode:

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

Update/save the post/page so you can use this target value in your link(s) URL (e.g. #some-id).

Click here for more info on target shortcodes

Creating id targets in HTML

Wrap your content in a div with an id attribute (recommended for better link highlighting) or add simple anchor points (with id attributes) before each content section. Examples:

<div id="section-1">
  <p>Section 1 content...</p>

<div id="section-2">
  <p>Section 2 content...</p>

<div id="section-3">
  <p>Section 3 content...</p>
<a id="section-1"></a>
<p>Section 1 content...</p>

<a id="section-2"></a>
<p>Section 2 content...</p>

<a id="section-3"></a>
<p>Section 3 content...</p>

Creating id targets in WordPress widget areas

Create targets in your widget areas (Appearance → Widgets) via plugin’s “Page scroll to id target” widget.
Keep in mind that all WordPress widgets have existing id values that you can use with your links. You can find these id values within each active widget under “Page scroll to id target” label. The option to display these values is “Display widgets id attribute” which is enabled by default.


Divi WordPress Theme

Creating links

page-scroll-to-id-target-menu The plugin is enabled by default on WordPress Menu links (Appearance → Menus), so you can start adding custom links and set their URL to the id/target you want to scroll to.

Edit your menu and add “Custom links” as these type of links allow us to enter a custom URL with the id we want. Your links URL should be in the form of #some-id,, /page/#some-id etc.

Please note that if you want your links to work from other/different pages, you’ll need to insert the full address with the target id in their URL (e.g. or the relative-root URL (e.g. /page/#some-id).

tinymce-custom-btn-ps2id-link In post visual editor, click the toolbar button “Insert/edit Page scroll to id link” to create a link at the cursor position in the editor or from text you’ve already selected.

page-scroll-to-id-link-modal In “Page scroll to id link” modal insert the link’s URL and text. The URL should be in the form of #some-id,, /page/#some-id etc. When ready, click “OK” and the link will appear in the editor. You can edit the link via both “Insert/edit link” and “Insert/edit Page scroll to id link” buttons, as well as inline.

“Page scroll to id link” modal provides additional options like “Offset” and “Custom class(es)” that can be used to change link’s offset, its scroll duration/speed etc.

In post visual or text editor, enter [ps2id url='#some-id']link text[/ps2id] in the place you want to create the link and set the url attribute and link’s text to the values you want. The shortcode provides the same options as plugin’s “Insert/edit Page scroll to id link” toolbar button via attributes.

Any link with ps2id class or m_PageScroll2id rel attribute value will be handled by the plugin. For example:

<a href="#some-id" class="ps2id">link text</a>
<a href="#another-id" rel="m_PageScroll2id">link text</a>

You can instruct “Page scroll to id” to handle any link in your page(s) by using the “Selector(s)” field in plugin settings.
If you need to enable “Page scroll to id” on all links with URL containing a hash (#), insert the following value in “Selector(s)” field:

Click here for more info on “Selector(s)”


Links highlighting

Each time a target element is visible on the screen (i.e. is within the viewport), the plugin adds the mPS2id-highlight class to its associated link or links (i.e. the links that scroll to this target). You can use this class in your theme’s stylesheet or custom CSS to style the current/active link(s), e.g.
a.mPS2id-highlight{ background: #ff0; }

Common case scenario and example

Lets say you have a sticky menu containing links that scroll to various targets/sections within the page. Your links text color is black (which may be set by your theme or some other stylesheet):

.memu-item a{ 
    color: black; 

When scrolling through page sections (i.e. targets) you want the link of the visible/current target to become red. You can do this by adding the following CSS:

.memu-item a.mPS2id-highlight{ 
    color: red; 

Notes and more info

The default highlight classes for the links are: mPS2id-highlight, mPS2id-highlight-first and mPS2id-highlight-last (you can change these class-names in plugin’s settings if you want).

For more information about the highlight classes and options see “Classes & highlight options”, “Highlight selector(s)” and FAQ below.


Offset scrolling for sticky menus

If your page has a top sticky/fixed-positioned menu, you’ll probably need to use plugin’s “Offset” option in order to prevent the menu from overlapping your content. This option allows us to shift (i.e. offset) scrolling, so in the case of a top sticky menu, we usually need to “stop” scrolling a few pixels before the target reaches the top of the page (to accommodate for the space the sticky menu occupies).

Go to Settings → Page scroll to id → Offset and insert an offset amount equal to your sticky menu height (in pixels). You can insert its height value as a number (e.g. 100) or you can insert your menu selector (e.g. #my-sticky-menu), so the plugin calculates its height automatically.

The plugin provides special selector expressions in order to define advanced offsets and work with responsive menus. For more info see “Offset” option.

Scrolling from/to different pages

The plugin has the option to scroll from/to different pages enabled by default. This means that when you click a link which points to a target id on another page, you’ll still get the smooth scrolling effect which will happen immediately after that page is fully loaded.

The only thing you’ll need is to make sure your links have the full address with the target id in their URL (e.g.

Video tutorial


Post a comment

Comments pages: 1 5 6 7

  1. thomas
    Posted on March 22, 2018 at 11:15 Permalink


    thanks for the great plugin 🙂

    is it possible to add a vertrical progress reading indicator in the widget like ?

    would be so great.

  2. alejandro
    Posted on March 10, 2018 at 16:52 Permalink

    is posible add the offset in the link?


    • malihu
      Posted on March 11, 2018 at 19:03 Permalink

      No, not in its URL. You can only have link-specific offsets via plugin’s toolbar button and shortcode (see more info here)

  3. Cedric
    Posted on March 9, 2018 at 03:44 Permalink

    Hi Malihu,

    I’m using your plugin and it works great, thank you.

    I have one question/issue about a behaviour with the browser url though.

    Is it possible to hide the hash value all the time? Because when I click on a menu link that opens another page, the hash value is still appended eventhough ” Append the clicked link’s hash value (e.g. #id) to browser’s URL/address bar” isn’t checked.

    Any advice?

    • malihu
      Posted on March 9, 2018 at 13:31 Permalink


      There’s no option to hide the hash value when coming from a different page/URL. The appended hash value is necessary so the plugin script knows where to scroll the page (since there’s no user triggered action, like clicking a link).

      It’s usually good for the user experience to have the hash value appended in browser’s URL when changing pages (it allows the user to bookmark sections, use browser’s back button etc.)

      This said, the only way (at least for now) to hide the hash when coming from other pages is to manually edit plugin’s script and changing some code. If you want I could tell you which file and how to modify it and see if it helps.

      • Cedric
        Posted on March 12, 2018 at 15:32 Permalink

        Hey Malihu,

        I’m definitely interested in knowing which file to modify?

        Thank you!


        • malihu
          Posted on March 12, 2018 at 17:12 Permalink

          OK do the following:

          1.First, edit your wp-config.php file (in your site root directory) and add the following:

          define('PS2ID_MINIFIED_JS', false);

          more info

          This will instruct the plugin to load the non-minified scripts that you can edit. You can add the above code before the “That’s all, stop editing! Happy blogging.” comment in wp-config.php.

          2.Go to plugin directory (e.g. /wp-content/plugins/page-scroll-to-id), open the js folder and edit jquery.malihu.PageScroll2id-init.js file.

          Change line 43 from:

          var href=window.location.href.replace(/#.*$/,"#");


          var href=window.location.href.replace(/#.*$/,"");

          You can change the line above or comment-out the original and add a new one with the modified code below it.

          Remove (or comment-out like below) lines 81-85:

          /* if(window.history && window.history.replaceState){ window.history.replaceState("","",_hash); }else{ window.location.hash=_hash; } */

          That’s it. Save the file and test you page.

          • Cedric
            Posted on March 14, 2018 at 11:00 Permalink

            It’s working like a charm. Thank you very much

        • malihu
          Posted on March 14, 2018 at 17:53 Permalink

          You’re welcome 🙂

          Please note that on the next plugin version I’ll probably add an option for this feature. So if/when you upgrade, you’ll just need to remove the constant from the wp-config.php and enable the related (new) option in plugin settings.

  4. Richard V. Landman
    Posted on February 28, 2018 at 00:58 Permalink

    well it’s a great plugin but I am having an issue with the jumps, when click on any “#” or anchor link to jump on page. It cuts down the fist 1 and a half lines.

    Can please guide me, maybe I am doing something wrong.

    • malihu
      Posted on February 28, 2018 at 01:25 Permalink

      I just checked your page ( and the plugin is not installed/activated.
      Not sure if this is the page/site you’re having trouble with or how can I help(?)

    • Thabo
      Posted on March 7, 2018 at 17:20 Permalink


      I heard the same issue. Try this plugin ‘iMeud’ It auto hide the header
      when scrolling. And what is amazing it re-appears again. So the user may be able to interact with sections properly.

      I think this is one of the best solution for this problem.

  5. Alejandro
    Posted on February 27, 2018 at 04:31 Permalink

    the plugin works well on the same page, it places some links with texts, and when you click it works correctly.

    <a href="" rel="nofollow">Que cosa es La Factoría</a> <a href="" rel="nofollow">Que hacemos en La Factoría</a> <a href="" rel="nofollow">Programas de La Factoría</a>

    But when I put the links in the main menu, the page appears as a jump and is not even framed as it should appear

    The link by itself from the browser works, …

    Might you help me?
    Thanks in advance

  6. Diane Kelly
    Posted on February 20, 2018 at 08:25 Permalink

    Where do I insert the “rel” code if I’m using the visual composer “button” settings?
    I can only put the URL link.

    • malihu
      Posted on February 20, 2018 at 18:06 Permalink

      If you want to enable the plugin on any link, button etc. without adding the rel or class attributes, do the following:

      Go to “Page scroll to id” settings and change “Selector(s)” option value to:


      Click save changes.

      The plugin will now be enabled on any link in your page that has a hash (#) in its URL.

  7. Alessandro
    Posted on February 14, 2018 at 13:18 Permalink

    Hi Malihu from Italy !

    I am using your plugin in my site and it is working wery well.

    However, when I navigate the first time on home page and select the last menu tab (contatti) the window does not scroll enough and I have to click two time to set ancor correctly. This appears too when I click on the same tab menu from another page. Is there a way around this?

    Thanks in advance!

  8. Ibraheem
    Posted on February 7, 2018 at 20:39 Permalink

    Hi Malihu from the UK!

    I am using your plugin in my site and it is working perfectly inside a page.

    However, when I navigate to my scroll id from another page (say the homepage) the window does not scroll enough. I think this is because I am using images with height set to 100vh (so the images load and re-size after the page is loaded). Is there a way around this?

    Thanks in advance!

    • malihu
      Posted on February 8, 2018 at 14:51 Permalink

      Hello Ibraheem,

      You could try using the delay for scrolling to target on page load option to how many milliseconds after the page is fully loaded, the scrolling will take place. For example insert 500 (i.e. half a second) in delay field, save changes and test your link(s).

      The issue you describe though sounds like you’re using a lazy-load image plugin (a script that loads images as you scroll down the page). Do you use such script/plugin?

  9. Tee
    Posted on February 1, 2018 at 20:47 Permalink

    I would like to be able to scroll between front page sections of my site using a button. So for instance. Front page one was a button on it that says Read More which would scroll me to front page 2 section. It used to work using:

    <a href="#front-page-2" rel="nofollow">Learn More</a>

    But it doesn’t work anymore.

    <a href="#text-31" rel="nofollow">Learn More</a>
    (but I don’t know how to add the button class to this.)

    Any advice?

    • Tee
      Posted on February 1, 2018 at 20:51 Permalink

      Let me try that again! I would like to be able to scroll between front page sections of my site using a button. So for instance. Front page one was a button on it that says Read More which would scroll me to front page 2 section.

      It used to work using: <a class="button" href="#front-page-2">Learn More</a>

      So I changed it to: <a href="#text-31" class="ps2id">Learn More</a> but I don’t know how to get my button back.

      Also, there are being done through the widget section.

      • malihu
        Posted on February 3, 2018 at 17:33 Permalink

        Change your button to include both classes:

        <a href="#text-31" class="button ps2id">Learn More</a>

        Is this what you need?

  10. joe z
    Posted on January 23, 2018 at 20:22 Permalink

    I have a question. Can you put more then 1 selector in the offset field> for exampe: #masthead and .mob-menu together. I am using to 2 menu’s together when it goes mobile. Is that possible?

    • malihu
      Posted on January 24, 2018 at 09:59 Permalink

      No, you cannot put 2 selectors in the “Offset” field.

      You can use plugin’s offset expressions in order to bypass the offset value in one of your menus (e.g. disable offset on mobile), but I’m not sure if this helps you.

      • joe
        Posted on January 26, 2018 at 16:18 Permalink

        Thank you for your response. This helps. What I did was use the class and set a value of 120 in the offset. It works. thanks,

  11. Garcia
    Posted on January 22, 2018 at 19:25 Permalink

    Hi from France Malihu !

    Thank you for this plugin really practical ! Easy to use however but i have a problem.

    I made my page with Builder SiteOrigin.

    When I click on my tabs menu I have my page scrolling on the desired section but each time it goes up the site before descending on my desired section. (always up & down grrrr…)

    And when I’m in the lower section of the page and I want to go back a section for example, it reloads the page at the top to immediately descend on the section.
    Is SiteOrigin a problem or who did something wrong?

    In the idea I will exactly like the result of your video !! : ^)

    Thank you very much for your help !!!!

    • malihu
      Posted on January 22, 2018 at 19:41 Permalink

      Hello and thanks for your comments 🙂

      Your issue is very easy to fix.

      Your server is configured to always redirect to the www subdomain. So when you go to it automatically redirects to

      Your links URL do not have the www part. That’s why when you click a link the page reloads (seems to go up before scrolling), instead of just scrolling to the section.

      You just need to add the www part in your links. For example, change “Accueil” URL from:


      and it’ll work 😉

      • Garcia
        Posted on January 22, 2018 at 19:59 Permalink

        Simple, fast, effective, just perfect !

        I am a beginner, I would probably need your help again for other settings such as the tab highlighted! 😀

        Thank you very much !


Comments pages: 1 5 6 7

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>