Support

Account

Home Forums General Issues Output WYSIWYG Link As Post ID

Solving

Output WYSIWYG Link As Post ID

  • Hi,

    I’ve created some anchor points that relate to various Post ID’s throughout my website, which when the user clicks on, takes them to a specific post further down the page. These work fine as I can set element ID’s using <?php the_ID(); ?> and clickable links using <a href="#<?php the_ID(); ?>" class="scroll-to-point"></a>.

    What I’m now trying to figure out is if a user wants to link to a post by inserting a link through the WYSIWYG field, with a caption of say ‘Find Out More’, how I can output that link as a Post ID instead of the full URL.

    I should also point out that I’m using Custom Post Types.

    I’m not sure if this is something that can be achieved through ACF or through editing the Permalinks in WordPress (which I’ve tried but had no success with).

    Thanks in advance!

    Kieran

  • You can’t do this with ACF and it would be difficult using WP to convert a link url to a post id. You might be able to add a filter to “the_content” that looks for urls and tries to convert them to an ID. You might be able to build your own shortcode to put into the content and let them select pages post object ACF field and then get the ID from that, but that’s not something that ACF can do and you’d need to build the shortcode PHP yourself.

  • Hi John,

    Thanks for responding so quickly! I totally understand, I think I need to figure out a new approach.

    One angle I’ve thought of is adding the same class to every link that is outputted by the WYSIWYG editor. Is that possible? So say on the front-end every link looked like:

    <a href="blahblah" class="scroll-to-link"></a>

    I’ve had a look through the TinyMCE documentation but everything seems to be weighted towards styling the editor – I haven’t come across anything that would help me add a class.

    Thanks!

  • You should look into adding a filter to the_content https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content. I wouldn’t know where to begin altering the editor. If you want to dig into that you might want to look into another forum where there’s people that have that knowledge.

  • Hi John,

    No worries, it was a long–shot anyway! Thanks for your help, I’ll take a look through this and see what I can figure out.

    Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Output WYSIWYG Link As Post ID’ is closed to new replies.