i have a very long article created by a user in Wordpress , i want to show a navigation on every article page with links to the titles of the current article.
e.g:
<h1 id='title1'>Title 1</h1>
bla bla bla
<h1 id='title2'>Title 2</h1>
bla bla
my navigation on this page would be <a href="#title1">Anchor link to title 1</a>
The example above is how you would hardcode it, but my article text is obviously variable and so are my links, what is the best way to tackle this with php?
Edit: the situation is not exactly like the example, the user puts text into a wordpress text editor field and doesnt want to write html tags, so the navigation needs to be filled with the titles that the user has put in the text field and those link to the variable titles on the page. (with an anchor i assume)