sitemap icon indicating copy to clipboard operation
sitemap copied to clipboard

A way to exclude an entry from the sitemap?

Open shantamg opened this issue 9 years ago • 5 comments

Wondering if there's a way to exclude certain entries from the sitemap. We have some entries that we want only accessible by a shared url, and we don't want linked on the site or reachable by searching google.

Could there be a way to hook into the creation of the sitemap and skip an entry based on custom logic?

shantamg avatar Dec 16 '16 00:12 shantamg

The only way right now is probably to disable the section in the sitemap control panel settings and write your own craft plugin that uses renderSitemap and the service methods to add some of your entries back in.

But I think the use case you are describing is pretty common and we should simplify craft-sitemap to support it.

How about adding an option to the control panel? I created a quick mockup how it could look: craft-wireframe

When you click on the pencil icon it would show a dialog to select one of your fields and enter a value to filter for.

Would that work for you, @shantamg?

groe avatar Dec 16 '16 16:12 groe

That's what I was thinking: turn the section off and then add only the ones I want using the hook. But you're right, it would be way better not to have to write another plugin just to do that.

Your include if idea is great. What if that field accepted twig code that was expected to return a boolean? If you want it to be even simpler, it could just take the handle of a boolean field and leave it up to the user to create that boolean field. I use preparse plugin a lot anyway so that could be a way to do it.

shantamg avatar Dec 16 '16 17:12 shantamg

Might setting criteria in the plugin's config file be an acceptable solution? Something like the Elements API approach: https://github.com/pixelandtonic/ElementAPI/blob/master/README.md

joshuabaker avatar Dec 18 '16 19:12 joshuabaker

I have just added an option to use any existing lightswitch-field to include/exclude entries:

image

Feel free to give it a try.

groe avatar May 11 '17 12:05 groe

Hi there,

Running into an issue with this. Since this is pulling in all lightswitch fields, we have a bunch of fields being pulled in, which are all a lightswitch field (as you said) See screenshot: Screen Shot 2019-07-24 at 3 30 48 PM

I added a lightswitch called "Index page in search engines" and attempted to update the dropdown with that value. However, upon saving it and opening the sitemap settings page back up it did not save the value. I attempted seeing the default value toggle switch to off/on, but no change. I thought it strange, because we haven't run into something like that before.

To note: The sitemap is also not populating (which makes sense, since nothing meets the requirements)

Do you know how I can potentially get this resolved?

Thanks in advance,

taylorganser avatar Jul 24 '19 20:07 taylorganser