+1-888-365-2779
Try Now
More in this section

Forums / Suggestions / SEO fields for news and blog items

SEO fields for news and blog items

45 posts, 0 answered
  1. John
    John avatar
    7 posts
    Registered:
    10 Jun 2013
    05 Jan in reply to Svetoslav Manchev
    Link to this post
    Svetoslav,

    I arrived here through another support ticket asking about adding OpenGraph meta tags, and this solution is useless for that scenario. 

    I need a way to add custom meta tags (e.g. <meta property="og:title" content="The Rock" />), not just the title, keywords and description. 

    So far it seems like the short answer is I can't do that, can you provide me with any insight into an approach that I'm missing?     
  2. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    Registered:
    01 Dec 2016
    06 Jan
    Link to this post
    Hi,

    You can use the ASP.NET API to modify the Page head element like so:

    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlMeta tag = new HtmlMeta();
        tag.Attributes.Add("property", "og:title");
        tag.Content = Page.Title;
        Page.Header.Controls.Add(tag);
    }

    You can create a simple user control with that code and place it on your template. It will correctly generate the OpenGraph tag with the page's title.

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. John
    John avatar
    7 posts
    Registered:
    10 Jun 2013
    07 Jan in reply to Velizar Bishurov
    Link to this post
    Velizar, 

    We're using pure mvc Feather, this won't work. 
  4. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    29 Nov 2016
    08 Jan
    Link to this post
    Hello John,

    You can check the below article for more information how to achieve your requirements in MVC:
    http://www.sitefinity.com/developer-network/knowledge-base/details/mvc-modify-page-title-and-meta-data

    I hope this helps.

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Erik
    Erik avatar
    7 posts
    Registered:
    03 Aug 2015
    08 Jan in reply to Svetoslav Manchev
    Link to this post

    John, this is the right answer.  See my solution -- MetaDescription is a custom field we created off of the BlogPost Content Model.

     

    public class MetaDataAttribute : ActionFilterAttribute
        {
            private string metaDescription;

            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
               var actionParameters = filterContext.ActionParameters;

               if (actionParameters.ContainsKey("item"))
               {
                   var item = actionParameters["item"] as Content;
                   if (item != null)
                   {
                       this.metaDescription = item.GetValue<string>("MetaDescription");
                   }
                }
            }

            public override void OnActionExecuted(ActionExecutedContext filterContext)
            {
                filterContext.Controller.ViewBag.Description = this.metaDescription;
            }
        }

  6. John
    John avatar
    7 posts
    Registered:
    10 Jun 2013
    08 Jan in reply to Erik
    Link to this post

    Erik,

    Thank you for taking the time to reply, but I'm not sure if I'm not explaining something properly or if I'm missing something. 

    Setting filterContext.Controller.ViewBag.Description = "whatever", adds the following meta tag to the head: 

    <meta name="description" content="whatever" />

    I'm not trying to add a description meta tag, I'm trying to do add a custom (opengraph) meta tag, this: 
    <meta property="og:title" content="The Rock" />

    Setting the Title, Keywords, and Description on the ViewBag does not help me at all... 

    Can you think of any way to add the custom meta tag?     

  7. Erik
    Erik avatar
    7 posts
    Registered:
    03 Aug 2015
    08 Jan in reply to John
    Link to this post

    John, you should be able to access any ViewBag parameters from your MVC _Layout -- e.g.

    filterContext.Controller.ViewBag.ogTitle= "The Rock"

    <meta property="og:title" content="@ViewBag.ogTitle" />

     

  8. John
    John avatar
    7 posts
    Registered:
    10 Jun 2013
    15 Jan in reply to Erik
    Link to this post

    Erik, 

    I have tried that, but the ViewBag.ogTitle is empty when the layout is rendered. What am I missing? 

  9. Erik
    Erik avatar
    7 posts
    Registered:
    03 Aug 2015
    15 Jan in reply to John
    Link to this post

    Hmmm, good question. . .  must be a Sitefinityism -- I've had some success submitting issues to the feather developers on github:

    https://github.com/Sitefinity/feather

  10. Jurgen
    Jurgen avatar
    11 posts
    Registered:
    11 Oct 2011
    22 Apr
    Link to this post

    Is adding a custom meta tag still not possible in feather? 

    It's hard to believe every sitefinity feather website is missing this functionality..

  11. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    Registered:
    01 Dec 2016
    22 Apr
    Link to this post
    Hi,

    You can achieve the desired behavior using an ActionFilter similar to the below one:

    using System.Collections.Generic;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using Telerik.Sitefinity.Frontend.News.Mvc.Controllers;
    using Telerik.Sitefinity.News.Model;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Web.Events;
      
    namespace SitefinityWebApp
    {
        public class FacebookMetaAttribute : ActionFilterAttribute
        {
            public string OgTitle { get; set; }
      
            public override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                base.OnActionExecuting(filterContext);
      
                if (filterContext.Controller.GetType() == typeof(NewsController) && filterContext.ActionDescriptor.ActionName == "Details")
                {
                    var actionParameters = filterContext.ActionParameters as IDictionary<string, object>;
                    var newsItem = actionParameters["newsItem"] as NewsItem;
                    if (newsItem != null)
                    {
                        this.OgTitle = newsItem.Title;
      
                        this.Register();
                    }
                }
            }
      
            private void Register()
            {
                EventHub.Unsubscribe<IPagePreRenderCompleteEvent>(OnPagePreRenderCompleteEventHandler);
                EventHub.Subscribe<IPagePreRenderCompleteEvent>(OnPagePreRenderCompleteEventHandler);
            }
      
            private void OnPagePreRenderCompleteEventHandler(IPagePreRenderCompleteEvent @event)
            {
                if (!string.IsNullOrEmpty(this.OgTitle))
                {
                    HtmlMeta tag = new HtmlMeta();
                    tag.Attributes.Add("property", "og:title");
                    tag.Content = this.OgTitle;
                    @event.Page.Header.Controls.Add(tag);
                }
            }
        }
    }

    To use the filter simply register it in the Global.asax like so:

    protected void Application_Start(object sender, EventArgs e)
    {
        Bootstrapper.Initialized += this.Bootstrapper_Initialized;
    }
      
    private void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
    {
        if (e.CommandName == "Bootstrapped")
        {
            GlobalFilters.Filters.Add(new FacebookMetaAttribute());
        }
    }

    The above example is tailored for the News widget and will set the og:title tag to the title of the currently viewed in details mode news item.

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  12. Jurgen
    Jurgen avatar
    11 posts
    Registered:
    11 Oct 2011
    25 Apr
    Link to this post

    Thank you Velizar! 

    This works like a charm!

  13. David
    David avatar
    114 posts
    Registered:
    19 Jul 2012
    21 May
    Link to this post

     

     

    I already have natural meta data fields in my Custom Modules.  I don't want to create a TitleTag, such that a user has to enter the same text as they have entered into another field say Title?  And yes the module is running and already has data in it, so I couldn't change the field names I understand if I wanted to - which I don't.  Why doesn't the Widget simply accept ANY field from a custom module, so I can set MetaTitleField to "Title" for instance and MetaDescriptionField to "Quote", etc.

    Update: doh it does didn't set PageTitleMode to Replace

  14. Brett
    Brett avatar
    10 posts
    Registered:
    07 Apr 2015
    09 Jun
    Link to this post

    Can someone suggest how I might be able to employ these solutions for the MVC widgets that are automatically generated when a dynamic content type is created within a custom module.

    How can I change the meta title and meta description when I am using one of these widgets?

     

    Any help would be appreciated!

    Thanks

  15. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    Registered:
    01 Dec 2016
    14 Jun
    Link to this post
    Hello,

    All you need to do is change the if clause in the Action Filter below and check whether the type is "DynamicContentController".

    Regards,
    Velizar Bishurov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
45 posts, 0 answered
1 2