Follow

TIL that Yoast overrides core ’s inline link popover in order to add `nofollow`/`sponsored` toggles. All us folk now need is for someone to do the exact same but add a `class` input field, so we can add `u-*` classes without having to constantly fight the block editor.

I’d much prefer this over a custom block (or some kind of meta box approach), as I want to be able to add such links anywhere in a post’s content.

(Thing is, you can “Edit as HTML,” but switching back to the [visual] link editor will remove your manually added attributes.)

Found some more code examples and am now able to either add a new formatting button that will trigger a completely inaccessible “href” popover but otherwise sorta works, or replace the core link button with something that, uh, will add an `a` tag with a class. But I’m a React noob. Plus, _all_ we need is for core links to accept a class.

Folks have been wanting a way to easily extend these links forever—three years, at least; there’s several GitHub issues—so not gonna get my hopes up. I did, however, just implement a different approach, where I add, e.g., a `u-bookmark-of` class to a _paragraph_ block, and a `the_content` filter then _removes_ that class and adds it to that paragraph’s first _link_ instead. Hacky, but probably more robust than “Edit as HTML.”

@jan Jan, I believe there are programmic ways of accessing the blocks. Either by filter or some other method:

awhitepixel.com/blog/add-custo

@nathand Custom blocks, patterns, or variations could be very handy, too, but the one thing I would really like is a way to easily address _inline_ links, e.g., those inside a paragraph block. (You’d pretty much have to create your own `Format`, i.e., what Yoast does.) One thing I could probably do, tho, is just add a class to the parent block and then let the `the_content` filter, i.e., PHP, handle the rest.

Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!