Workaround for CMS custom code embeds in rich text elements

Use this instead:

<script>
/* Morphs any paragraph that is wrapped in '<' and '>' into an embed */
var Webflow = Webflow || [];
Webflow.push(function() {
  $('.w-richtext p').each(function() {
    if(this.innerHTML.indexOf('&lt;') == 0 && this.innerHTML.match(/&gt;$/) != null) {
      this.innerHTML = this.innerText;
    }
  });
});
</script>

Or even this:

<script>
var Webflow = Webflow || [];
Webflow.push(function() {
  $('.w-richtext p').html(function() {
    return $(this).html().indexOf('&lt;') == 0 && $(this).html().match(/&gt;$/) != null ? $(this).text() : $(this).html();
  });
});
</script>

Hint: You can omit the line var Webflow = Webflow || []; if you place custom JavaScript code in the Page Footer or Site Footer.


Looking for code highlighting in CMS richtext field?

10 Likes