SEO fields for news and blog items - Ideas & Feature Requests - Ideas & Feature Requests - Progress Community
 Ideas & Feature Requests

SEO fields for news and blog items

  • Hello Erik,

    Thank you for the shared solution with the community.

    It is highly appreciated.

    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
     
  • 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?     
  • 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
     
  • Velizar, 

    We're using pure mvc Feather, this won't work. 
  • 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;
           
       

  • 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?     

  • 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" />

     

  • 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
     
  • Erik, 

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

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

    github.com/.../feather

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

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

  • 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
     
  • Thank you Velizar! 

    This works like a charm!

  •  

     

    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

  • 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