草庐IT

seo - Umbraco 7 SEO 标签

coder 2024-03-02 原文

我有一个网站,我想在 Umbraco 中为其创建 SEO 标签。我想知道它是如何完成的?有什么最佳实践文件或建议吗?

最佳答案

我不是 SEO 专家,但希望下面的代码片段可以帮助您入门

元数据

在页面上我添加了一些属性。如果您按文档类型、继承或组合来做,您可以选择。我定义了以下属性。

  • 页面标题,我希望它与页面名称有所不同。不确定它是否有任何不同 - 但我希望它能让我的文章的更多焦点词出现在页面标题或页面名称中。我放在 <head> 中的页面名称部分,页面标题作为文章/主要内容的一部分。

  • Page snippet,我的目标是尽可能短,并且大部分少于 160 个字符。文章中使用了页面片段,以及元数据的摘要。

  • 页面标签,用于元数据关键字以及网站上的水平内容导航。

  • 特色图片,虽然严格来说不是 SEO 的一部分,但作为使内容对社交媒体友好的策略的一部分很重要。

  • 作者,可能对 SEO 很重要,我有主要作者的属性(property),作为成员属性(property),我注册了 facebook 个人资料页面。

我已经开始编写 Razor 宏,但它需要做更多的工作,但对我来说效果很好。我将它作为一个宏运行在 <head> 中部分。

@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{  
    string domain = "https://" + HttpContext.Current.Request.Url.Host;
    string site_name = "sitename";
  string og_title = CurrentPage.Name; 
    string og_image = "";
    string og_description = "Description here";
    string facebookPageAuthor = "https://www.facebook.com/xx";
    string facebookPageSite = "https://www.facebook.com/xx";
    string authorName = "asdf";
    int authorId = 1099;
    string url = domain + CurrentPage.Url;
    string facebookAppId = "12341234";
    string twitterUserAuthor = "@asdf";
    string twitterUserSite = "@qwer";
    string logoUrl = domain + "/media/1006/logo.png";
    DateTime createDate = CurrentPage.CreateDate;
    DateTime updateDate = CurrentPage.UpdateDate;

    if (CurrentPage.pageTitle != null && !(CurrentPage.pageTitle is Umbraco.Core.Dynamics.DynamicNull))
    { og_title = CurrentPage.pageTitle;}

    @* Check if this page has snippet, and use it exists *@
    if (CurrentPage.pageSnippet != null && !(CurrentPage.pageSnippet is Umbraco.Core.Dynamics.DynamicNull))
    { og_description = CurrentPage.pageSnippet; }

    @* Check if this page has featured image, and crop to facebook preferred crop size (1200x630px). Use parent page default image it exists *@      
    if (CurrentPage.featuredImage != null && !(CurrentPage.featuredImage is Umbraco.Core.Dynamics.DynamicNull))
    {   
        var featImage = Umbraco.TypedMedia((int)CurrentPage.featuredImage);
        og_image= featImage.GetCropUrl("1200x630"); }
    else 
    { 
        og_image = Umbraco.Media(CurrentPage.AncestorsOrSelf(1).First().featuredImage).GetCropUrl("1200x630"); 
    }

    @* Check if author has facebook page *@
    if ((int)CurrentPage.author >0)
        { 
        authorId = (int)CurrentPage.author;
        }

        var authorModel = Members.GetById(authorId);
        authorName = (string)authorModel.Name; 
        facebookPageAuthor = (string)authorModel.GetProperty("facebookProfilePage").Value; 

}   
<meta property="og:title" content="@og_title" />
<meta property="og:site_name" content="@site_name" />
<meta property="og:url" content="@url" />
<meta property="og:description" content="@og_description" />
<meta property="og:image" content="@domain@og_image" />
<meta property="fb:app_id" content="@facebookAppId" />
<meta property="og:type" content="article" />
<meta property="og:locale" content="en_US" />
<meta property="article:author" content="@facebookPageAuthor" />
<meta property="article:publisher" content="@facebookPageSite" />
<meta name="twitter:title" content="@og_title" />
<meta name="twitter:description" content="@og_description" />
<meta name="twitter:image:src" content="@domain@og_image" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@twitterUserSite" />
<meta name="twitter:creator" content="@twitterUserAuthor" />

<script type="application/ld+json">
{
  "@@context": "http://schema.org",
  "@@type": "NewsArticle",
  "mainEntityOfPage":{
    "@@type":"WebPage",
    "@@id":"@url"
  },
  "headline": "@og_title",
  "image": {
    "@@type": "ImageObject",
    "url": "@domain@og_image",
    "height": 630,
    "width": 1200
  },
  "datePublished": "@createDate.ToString("o")",
  "dateModified": "@updateDate.ToString("o")",
  "author": {
    "@@type": "Person",
    "name": "@authorName"
  },
   "publisher": {
    "@@type": "Organization",
    "name": "domain.com",
    "logo": {
      "@@type": "ImageObject",
      "url": "@logoUrl",
      "width": "660",
      "height": "675"
    }
  },
  "description": "@og_description"
}
</script> 

面包屑

用于使用微数据制作面包屑的宏对 SEO 很有用。

@using Umbraco.Web
@using Umbraco.Web.Mvc
@using Umbraco.Core
@using System.Web
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@*
    This snippet makes a breadcrumb of parents using an html ordered list.
    It makes metadata available for search engines in the Microdata format.
    The CSS is customised for Bootstrap 4
*@

@if (Model.Content.Ancestors().Any())
{
    var pageAncestors = Model.Content.Ancestors().OrderBy("Level");
<div>
    <ol class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">       
        @foreach (var page in pageAncestors)
        {
                <li class="breadcrumb-item" itemprop="itemListElement" itemscope
                    itemtype="http://schema.org/ListItem">
                    <a itemscope itemtype="http://schema.org/Thing"
                       itemprop="item" href="@page.Url">
                        <span itemprop="name">@page.Name</span>
                    </a>
                    <meta itemprop="position" content="@page.Level" />
                </li>
        }
        <!-- And add the current page -->
        <li class="breadcrumb-item active" itemprop="itemListElement" itemscope
            itemtype="http://schema.org/ListItem">
                <span itemprop="name">@Model.Content.Name</span>
        </li>
    </ol>
</div>
}

站点地图

我的站点地图应该提交给搜索引擎。宏可以是这样的:

@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using Umbraco.Core.Models
@using Umbraco.Web
@using System.Linq;
@{ Layout = null;
Response.ContentType = "text/xml";
}<?xml version='1.0' encoding='UTF-8' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemalocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
@ListChildNodes(Model.Content.AncestorOrSelf(1))
</urlset>

@helper ListChildNodes(IPublishedContent startNode)
{
    const int maxLevelForSiteMap = 100;

    foreach (var node in startNode.Children.Where(x => Umbraco.MemberHasAccess(x.Id, x.Path)).Where(x => !Umbraco.IsProtected(x.Id, x.Path)).Where(x => x.IsVisible()))
    {
        if (node.TemplateId > 0)
        {
            <url>
                <loc>@node.UrlWithDomain()</loc>
                <lastmod>@(string.Format("{0:s}+00:00", node.UpdateDate))</lastmod>
                @{
                    var freq = node.GetPropertyValue<string>("SearchEngineSitemapChangeFreq");
                    var pri = node.GetPropertyValue<string>("SearchEngineSitemapPriority");
                }

                @if (!string.IsNullOrEmpty(freq))
                {
                    <changefreq>@freq</changefreq>
                }
                @if (!string.IsNullOrEmpty(pri))
                {
                    <priority>@pri</priority>
                }
            </url>
        }

        if (node.Level <= maxLevelForSiteMap && node.Children.Any())
        {
            @ListChildNodes(node)
        }
    }
}

关于seo - Umbraco 7 SEO 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39890374/

有关seo - Umbraco 7 SEO 标签的更多相关文章

  1. ruby - 在院子里用@param 标签警告 - 2

    我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?

  2. css - 用 watir 检查标签类? - 2

    我有一个div,它根据表单是否正确提交而改变。我想知道是否可以检查类的特定元素?开始元素看起来像这样。如果输入不正确,添加错误类。 最佳答案 试试这个:browser.div(:id=>"myerrortest").class_name更多信息:http://watir.github.com/watir-webdriver/doc/Watir/HTMLElement.html#class_name-instance_method另一种选择是只查看具有您期望的类的div是否存在browser.div((:id=>"myerrortes

  3. ruby - 如何用 Nokogiri 解析连续的标签? - 2

    我有这样的HTML代码:Label1Value1Label2Value2...我的代码不起作用。doc.css("first").eachdo|item|label=item.css("dt")value=item.css("dd")end显示所有首先标记,然后标记标签,我需要“标签:值” 最佳答案 首先,您的HTML应该有和中的元素:Label1Value1Label2Value2...但这不会改变您解析它的方式。你想找到s并遍历它们,然后在每个你可以使用next_element得到;像这样:doc=Nokogiri::HTML(

  4. ruby-on-rails - 在 Label 标签中嵌套 Ruby on Rails HAML 复选框 - 2

    我有以下不起作用的代码:=form_for(resource,:as=>resource_name,:url=>session_path(resource_name),:html=>{:class=>"well"})do|f|=f.label:email=f.email_field:email=f.label:password=f.password_field:password-ifdevise_mapping.rememberable?%p=f.label:remember_me,:class=>"checkbox"=f.check_box:remember_me,:class=>"

  5. ruby - 如何使用 Nokogiri::XML::Builder 生成动态标签? - 2

    我正在遍历数组中的一组标签名称,我想使用构建器打印每个标签名称,而不是求助于“我认为:builder=Nokogiri::XML::Builder.newdo|xml|fortagintagsxml.tag!tag,somevalendend会这样做,但它只是创建名称为“tag”的标签,并将标签变量作为元素的文本值。有人可以帮忙吗?这个看起来应该比较简单,我刚刚在搜索引擎上找不到答案。我可能没有以正确的方式提问。 最佳答案 尝试以下操作。如果我没记错的话,我添加了一个根节点,因为Nokogiri需要一个。builder=Nokogi

  6. ruby-on-rails - 如何将变量值插入 ERB 模板中的 HTML 标签? - 2

    我有一个偏爱:如何将像o.office这样的值插入到属性中?value="#{o.office}"无效。 最佳答案 'type='text'/>或者你可以使用表单助手 关于ruby-on-rails-如何将变量值插入ERB模板中的HTML标签?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/6172174/

  7. ruby-on-rails - 在 Ruby 中提取 IMG 标签 - 2

    是否可以从Ruby中的HTMLblock中提取IMG标签(或只是IMG标签的src属性)?例如,如果我有一个HTMLblock,例如:Loremipsumdolorsitamet,laboreetdoloremagnaaliqua.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.我可以通过正则表达式或其他方法只提取IMG标签或该IMG标签的src吗?提前感谢您的任何建议! 最佳答案 使用Nokogiri:re

  8. ruby-on-rails - 使用 stock_quote gem 中的股票报价作为 acts_as_taggable gem 中的标签? - 2

    所以我正在使用acts_as_taggablegem提供的标签。这些帖子是我正在标记的内容。我怎么能说类似=>的东西(这里是伪代码)ifacollectionofPostshasatagwithacorrespondingStockQuote,displaythestockquote所以现在我有一个acts_as_taggable的Post资源。这是我的帖子索引操作现在的样子:defindex@stock=StockQuote::Stock.quote("symbol")ifparams[:tag]@posts=Post.tagged_with(params[:tag])else@po

  9. ruby-on-rails - 如何在 ruby​​ on rails 中为表单字段使用 span 标签? - 2

    在我的表单中,我使用了如下的span标签:在我选择值后,它在HTML中看起来像下面这样:Antony问题是当我们创建表单时,id没有获取到数据库的值。我不知道确切的问题是。我想使用此内容标签而不是text_field来获取值。谢谢。 最佳答案 当您提交HTML表单时,唯一被POST的值是输入字段中的值,例如文本字段、选择、复选框、按钮等。页面上的内容——无论是否在跨度内--不会发回服务器。这不是Rails的问题,这只是HTML的工作方式。我不太确定你在这里想做什么,但是当你想显示一个值(而不是在输入框中)并将值与表单一起发回时,一种

  10. sql - 如何查询具有 3 个标签的事件? - 2

    我有以下模型:activity.rbtag.rbtagging.rb标签是事件和标签的连接模型。我想搜索具有2个或更多标签的事件。我如何在Rails中执行此操作?例如:我有tag1=Christmas,tag2=Florida,tag3=John如果存在,我想找到tag1、tag2和tag3存在的Activity。[编辑]我最终做了什么:tags=[tag1,tag2,tag3]activities=[]tags.eachdo|tag|activities如果任何组值的大小等于tags.size,则该事件包含所有标签。 最佳答案 如

随机推荐