I'm exploring Prismic to start my own blog, and I've created a sample structure for the same.
but now, I'm facing issue because I want to add rel="nofollow" to external links from my content, this is very important from SEO perspective, but as of now I can only see option to open this link in a new tab.
So, My question is how can I give nofollow attribute to content added via rich text field.
I’ve already checked that guide before posting this question, but that guide is to add “nofollow” element to Link field, But I’m talking about the link that are mentioned in the Rich text editor.
Let me give you more clear idea.
I’m creating a blog and for that to add content, I’m using Rich text editor field, where I’m getting basic option to add content, headings, etc.
Here I can add hyperlink to text as well, but there is no option for me to give nofollow attribute to it.
And considering blog structure I can’t use Link element as it is not a right option.
Check attached screenshot for better understanding.
@showupdigitalmedia the principle described in the article also applies to rich text fields you would define a label such as nofollow_link and apply that label to the link selection in the rich text field. Then in your renderer, if you have the label and are rendering a link you can add the nofollow attribute.
Hello again, thank you a lot for giving us more details!
You’re in the right path, the only thing that you’ll need to implement now is an HTML Serializer. This function helps you customize the HTML output of a Rich Text Field.
Afterwards, you only need to pass the HTML serializer to your Rich text field. Which technology are you using to template?
Actually you don’t necessarily need to define a full fledged html serializer which is quite a lot of work if all you need is to override rendering for a single element, prismic-react now supports an elements property:
<RichText
render={document.data.text_field}
elements={{
hyperlink: function a({ children, data }) {
return <a>{children}</a>;
}
}}
/>
I don’t have the shape of data at hand, but you should be able to inspect it to find out how to detect the label and convert it into a no-follow attribute.