1

I like the default add link dialog in the wordpress editor. IT allows for easy linking to internal pages. I need to modify the output of those internal links.

Right now its outputting:

<a href="page url" title="linked page title">my text</a>

I need it to be:

<a href="page url" title="linked page title" data-id="linked page id">my text</a>

I need the linked page id to be set in a data attr. Is this possible with a action/hook

Thank you

1 Answer 1

0

I'm in a hurry so don't have time to provide any code, pseudo or otherwise, but you could probably do this in the the_content filter by using a regex to find all links and for each one find the page/post ID using url_to_postid and then replacing as appropriate.

Good luck!

3
  • This makes sense, how much a performance hit will I take? Commented Jul 24, 2014 at 15:16
  • Good question, that I don't know the answer to. The regex itself should be negligible, but the other function is probably a db query each time, so a page with lots of links could hammer the database a bit. Commented Jul 24, 2014 at 21:35
  • Got it. Its a functional answer to the question. Commented Jul 24, 2014 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.