Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian Milinski 42 posts 165 karma points
    Oct 17, 2016 @ 20:21
    Brian Milinski
    0

    Rich Text Editor for Meta Description Tag

    Hi, I am wondering if anyone has run into the issue of using a rich text editor that they are putting content into for their meta description for SEO. The problem I am running into is that all of the HTML tags and links are coming along for the ride, and I don't necessarily want this to be occurring. Is there an elegant way to just get the text from the rich text editor.

    Calling .ToString() gives me an ugly looking meta description.

    @if (pageVariables.HasValue("copy"))
    {
        <meta name="twitter:description" content="@umbraco.library.RemoveFirstParagraphTag(Html.Raw(pageVariables.copy).ToString())">
    }
    
  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Oct 17, 2016 @ 22:26
    Marc Goodson
    101

    Hi Brian

    I tend to use a text area for these meta descriptions, so that I'm not putting html inside the content attribute of a meta tag, however...

    There is an UmbracoHelper method called StripHtml that you could use to remove the html you do not want here:

    @Umbraco.StripHtml("<blink>Stop the blinking</blink>");
    

    and you may also want to limit the number of characters of the description that gets written into the content attribute, if so there is also a Truncate method on the UmbracoHelper... eg

    @Umbraco.Truncate("I wish I was a tweet, at least then I get 140 chars", 10, true)
    

    Other Umbraco Helpers detailed here:

    https://our.umbraco.org/documentation/reference/querying/umbracohelper/

    regards

    marc

  • Brian Milinski 42 posts 165 karma points
    Oct 18, 2016 @ 13:18
    Brian Milinski
    0

    Marc,

    Thanks so much for your quick response. This is exactly what I was looking for, and this allows me to leave my underlying Umbraco structure unchanged. Win. :)

    Brian

Please Sign in or register to post replies

Write your reply to:

Draft