How to scroll to a shortcode-generated anchor

by LarryG001   Last Updated July 17, 2017 10:08 AM

I'm stuck...

I have a shortcode in a WP page. The PHP function in the shortcode does the following logic:

if (isset($_GET['some_id'])) { // Get single item
   Query MySQL table to get the item with the id='some_id'
   // Show item
   $html .= 'Some html';
   $html .= '<div id="div_id">blabla</div>'; // <-- Here is the problem zone
   return $html; 
   // All of the above works perfectly
   }
else { // Show list of items
   Query MySQL table to get list of items
   //Show list
        foreach ($results as $result)
            $html .= $result->titel.' <a href="'.esc_url( add_query_arg( 'some_id', $result->id, 'The URL of the current page' ) ).'">Get details</a>';
        return $html;
        }

This code does what it should do: The page first shows the list of items (b/c URL parameter some_id is not set).

Then, in the list, I click on "Get details". The very same page reloads (now the parameter "some_id" is set) and I get the corresponding output with the div id="blabla" somewhere.

However, I want the page to then scroll directly to the div id ="blabla", but I'm not able to make that work. I tried javascript, jquery, and also putting the #blabla in the URL (url/?some_id=3#blabla)... Nothing works...

Any hint/pointer greatly appreciated. Thank you. Larry

Tags : shortcode


Related Questions


Problem with the_content() shortcode

Updated April 04, 2015 02:03 AM

Snippet for extern page

Updated April 08, 2015 23:03 PM


Adding shortcode to the main menu

Updated June 29, 2015 13:03 PM

Add shortcode support to custom field

Updated April 15, 2015 20:03 PM