Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to set meta keywords? #139

Closed
ianleeder opened this issue Dec 28, 2022 · 3 comments
Closed

Possible to set meta keywords? #139

ianleeder opened this issue Dec 28, 2022 · 3 comments

Comments

@ianleeder
Copy link
Contributor

Similar to #123, I'm kind of surprised to find that I can't set Keywords.

Any progress on updating the wiki?
image

@colinfyfe
Copy link

Hi @ianleeder, I've just discovered this package today and hats off to @patrickdemooij9 as it covers 99% of my use cases too with meta tags, sitemap.xml, GTM and Hubspot integration being the immediate boxes ticked. I'm new to both .NET and Umbraco but Patrick's TODO encouraged me to dive into the source to see if I could figure this one out. I'm not saying this is correct - Patrick might recoil in horror when he sees this implementation - but I've added a custom keywords field between the description and canonical URL.

seotoolkit-keywords-field

I created an SeoKeywordsField class based on a modified SeoDescriptionField:

using Microsoft.AspNetCore.Html;
using SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors;
using SeoToolkit.Umbraco.MetaFields.Core.Constants;
using SeoToolkit.Umbraco.MetaFields.Core.Interfaces.SeoField;
using SeoToolkit.Umbraco.MetaFields.Core.Models.SeoFieldEditors;
using Umbraco.Cms.Core.Composing;

namespace Cf.Umbraco.Extensions
{
    [Weight(210)]
    public class SeoKeywordsField : ISeoField
    {
        public string Title => "Meta Keywords";
        public string Alias => "metaKeywords";
        public string Description => "Meta keywords for the page";
        public string GroupAlias => SeoFieldGroupConstants.MetaFieldsGroup;
        public Type FieldType => typeof(string);

        public ISeoFieldEditor Editor => new SeoFieldFieldsEditor(new[] { "Umbraco.TextBox", "Umbraco.TextArea", "Umbraco.TinyMCE" });

        public ISeoFieldEditEditor EditEditor => new SeoTextAreaEditEditor();

        public HtmlString Render(object value)
        {
            return new HtmlString($"<meta name='keywords' content='{value}'/>");
        }
    }
}

... then created an Umbraco IComposer to register the new type:

using SeoToolkit.Umbraco.MetaFields.Core.Collections;
using SeoToolkit.Umbraco.MetaFields.Core.Composers;
using Umbraco.Cms.Core.Composing;

namespace Cf.Umbraco.Extensions
{
    [ComposeBefore(typeof(MetaFieldsComposer))]
    public class SeoKeywordComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.WithCollectionBuilder<SeoFieldCollectionBuilder>().Add<SeoKeywordsField>();
        }
    }
}

This hasn't been extensively tested and I'll let Patrick advise on whether it's the right approach or not but it certainly seems to be working for me in my local dev environment.

@patrickdemooij9
Copy link
Owner

Totally missed this issue, so sorry for the late reply.

What @colinfyfe has posted is indeed the correct way of doing this. It is exactly the way that I would have done it. And I should indeed update the documentation with these examples.

As for why the package doesn't have meta keywords is because they aren't used by Google anymore (and many other search providers). Is there a reason on why you would need them @ianleeder? Would love to hear the use case for them if they aren't used that much anymore.

@ianleeder
Copy link
Contributor Author

Wow. Thanks for this example @colinfyfe. Even if I don't use it for Keywords, it still may come in very handy.

@patrickdemooij9 I obviously haven't kept up to date on SEO techniques! The client included keywords on their wishlist somewhere, but if it's no longer used for SEO I'll simply pass that on to them. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants