Showing posts with label SEO. Show all posts
Showing posts with label SEO. Show all posts

Tuesday, February 21, 2017

Setting SharePoint SEO (Search Engine Optimization) settings using CSOM

I wanted to add viewport meta to my SharePoint page to make it responsive. The best way to do that I found and agreed with was to add it to Search Engine Optimization settings. Stefan Bauer has an excellent blog on it: http://www.n8d.at/blog/how-to-add-viewport-meta-without-editing-the-master-page/

So, next step was to be able to provision this via CSOM. So I wrote the following code does that:

public void SetSearchEngineOptimizationSettings(ClientContext ctx)
{
  var web = ctx.Web;
  web.AllProperties["seoincludecustommetatagpropertyname"] = "true";
  web.AllProperties["seocustommetatagpropertyname"] = "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1\" />";
  web.Update();
  ctx.ExecuteQuery();
}