gpt4 book ai didi

seo - Umbraco 7 SEO 标签

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:47:52 24 4
gpt4 key购买 nike

我有一个网站,我想在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com