November Happy Hour will be moved to Thursday December 5th.

How to change multiply (all) meta titles, descriptions and H1 at once?

Vote:
 

Hey, I'm SEO Manager and I need to change many Page Titles and other properties on my website. Is it possibilty to do it? What need to know?

#221646
Edited, Apr 22, 2020 21:30
Vote:
 

Hi Tomek, This is programmatically possible, but not sure how we can update  Page Titles as a content editor in a single shot. 

The code for Page Titles update in a single shot is here:

Page Type:

 [ContentType(DisplayName = "Meta Title Change", 
        GUID = "1059E3DB-CBB9-4110-B5EB-81C80D0C7449", 
        GroupName = Global.GroupNames.Specialized,
        Description = "Use this to change the page meta title.")]
    [SiteImageUrl]
    [AvailableContentTypes(IncludeOn = new[] { typeof(StartPage) })]
    public class MetaTitleChangePage : SitePageData
    {
    }

Controller:

public class MetaTitleChangePageController : PageControllerBase<MetaTitleChangePage>
    {
        private readonly IContentRepository _contentRepository;
        public MetaTitleChangePageController(IContentRepository contentRepository)
        {
            _contentRepository = contentRepository ?? throw new ArgumentNullException(nameof(contentRepository));
        }


        public ActionResult Index(MetaTitleChangePage currentPage)
        {
            var viewmodel = PageViewModel.Create(currentPage);
            return View("~/Features/MetaTitleChange/MetaTitleChangePage.cshtml", viewmodel);
        }

        [HttpPost]
        public ActionResult Change(MetaTitleChangePage currentPage, string title)
        {
            var contents = _contentRepository.GetChildren<SitePageData>(SiteDefinition.Current.StartPage).ToList();

            var count = 0;
            foreach (var item in contents)
            {
                var clone = item.CreateWritableClone() as SitePageData;
                if (clone != null)
                {
                    clone.MetaTitle = title;
                    _contentRepository.Save(clone, SaveAction.Publish, AccessLevel.Administer);
                    count++;
                }
            }


            ViewData["message"] = $"'{count}' pages meta title have been changed successfully.";

            var viewmodel = PageViewModel.Create(currentPage);
            return View("~/Features/MetaTitleChange/MetaTitleChangePage.cshtml", viewmodel);
        }
    }

View:

@using AlloyDemo.Models.ViewModels
@model PageViewModel<AlloyDemo.Features.MetaTitleChange.MetaTitleChangePage>
@if(ViewData["message"] != null)
{
    <div class="alert alert-success">
        @ViewData["message"]
    </div>
}
<div>
    <form action="@Url.ContentUrl(Model.CurrentPage.ContentLink)change" method="post">
        <input name="title" placeholder="Enter a meta title" />
        <input type="submit" value="Submit" />
    </form>
</div>

UI: 

#221670
Apr 23, 2020 3:28
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.