Jump to content

Native Way to Adjust Settings for URL/Slug Generation?


Lauren
 Share

Recommended Posts

Hi there,

Is there a native way to adjust how a page's name/url/slug is generated as you type? I'd like it to function similarly to WordPress, which filters out stop words like, "a", "to", "the", etc.

If there's not a way to do it natively, would you recommend a module that hooks into the event of when a new page is added?

A page's name seems like a pretty vital part of ProcessWire. So, I'm a bit hesitant about messing with it at all! What do the seasoned PW developers out there think? I'm I asking for problems by messing with the page name?

Thanks!

Lauren

  • Like 1
Link to comment
Share on other sites

Hi Lauren,

You'll need to hook into ProcessPageAdd::buildForm and potentially ProcessPageEdit::buildForm if you also want to change the name when the title is changed during a later edit.

You can get an idea of how to do this from my Page Rename Options module (https://github.com/adrianbj/PageRenameOptions/blob/master/PageRenameOptions.module#L65)

You can see that I have added some JS to override the native functionality when it comes to naming the pages.

You will be looking to add to/override the functionality in these files:

https://github.com/ryancramerdesign/ProcessWire/blob/6cba9c7c34069325ee8bfc87e34e7f1b5005a18e/wire/modules/Inputfield/InputfieldPageName/InputfieldPageName.js

https://github.com/ryancramerdesign/ProcessWire/blob/6cba9c7c34069325ee8bfc87e34e7f1b5005a18e/wire/modules/Inputfield/InputfieldPageTitle/InputfieldPageTitle.js

Hope that helps to get you started.

There is nothing wrong with messing with the page name - in fact it is possible to manually edit it by hand. The one thing that some don't agree on is whether it should ever be changed after it is originally created. I would personally rather the name matched the title, but others think it should never change due to SEO and broken links. I make use of the Page Path History module to deal with these - maybe not perfect, but typically the only time the titles will change is during development, so I am ok with it.

  • Like 7
Link to comment
Share on other sites

Hi Lauren,

I have thrown something together for you. It isn't well tested yet, but seems to be working fine. You can edit the StopWords.js file if you want to adjust the words that are removed. If there is general interest in this module, I might consider making it configurable.

Let me know how it goes for you.

PageNameRemoveStopwords.zip

Edited by adrian
New version
  • Like 7
Link to comment
Share on other sites

This is interesting because I was approaching some advnced automatic naming behind the scenes only last night during the page save process (so ignoring giving the visual indicator this will on the edit page) but in my case that was find because those pages needed no user control over the page names.

Very nice idea and keeps URLs shorter but I'm not sure it makes a difference to SEO any more to be honest, though I am no expert. Still, ProcessWire is all about providing the tools that in turn can provide more options so good work :)

  • Like 2
Link to comment
Share on other sites

Thanks Pete - I am not sure about the effect of removing StopWords on SEO either, but seemed like a nice quick module to whip up so thought I'd help out :)

Actually I have just revised the module. The first iteration completely overrode the InputfieldPageName.sanitize method. This new version just adds and applies a new method for removing the stopwords. This should be much safer in that we don't need to worry about overriding any updates that are made to that method in the PW core.

New version attached in my post above.

Link to comment
Share on other sites

Good work on helping out of course - I was more thinking out loud.

I think having just read up on it quickly it doesn't seem to matter much - see the final reply to the chosen answer here (which disagrees with that answer): http://stackoverflow.com/questions/9734970/better-seo-to-remove-stop-words-from-an-articles-url-slug as well as the comment further down about the fact that StackOverflow don't do it. Having checked that, nor do Slashdot and some other big sites.

In fact most search results about stopwords seem to relate to Wordpress plugins rather than anything official from Google saying it makes any difference.

I think it's one of those things that may have mattered in the past but not so much now. There are certainly some respectable SEO companies out there who aren't removing the stopwords from their own website URLs either.

But please don't take my word for it - as I say I was just thinking out loud and know very little about the subject so if someone finds a definitive answer somewhere from Google themselves then please do share as the short research I did wasn't really conclusive.

  • Like 4
Link to comment
Share on other sites

I have always tended to look at these as more of a problem in titles and so on than in URLs  - if you have a lot of "of" "in" "at" and so on, your titles are going to be waffly and probably too long for good SEO. Making the Title of the page neat and sensible means the resulting name will be the same - it is a copy writing problem.

Over use can also make bad copy - when being attentive to SEO, you should first and foremost be attentive to the audience. If removing all stop words from a URL or title turns it into gibberish, you have not done yourself any favours from either the SEO or readability point of view.

From the little I know, it seems like these days Google et al do not just remove all stop words - they have lists of phrases where stop words should be left alone and generally seem to be growing a more pragmatic approach to everything.

In these sorts of circumstances human editing is much better than automation. 

  • Like 3
Link to comment
Share on other sites

 If removing all stop words from a URL or title turns it into gibberish, you have not done yourself any favours from either the SEO or readability point of view. 

That sounds like the key issue in all this to me - very good point!

And Pete - thanks for those links.

Lauren will have some thinking to do when she finally gets back to this thread :)

  • Like 1
Link to comment
Share on other sites

<snip>

Lauren will have some thinking to do when she finally gets back to this thread :)

Indeed! Wow, such insightful, helpful answers. Thank you everyone!

Adrian, the module you whipped up...so cool and super simple too. Love it. I installed it and tested it out; it's exactly what I was hoping for when I first started thinking about how to accomplish it. I was hoping you could modify the built-in JS behavior like that. Really nifty.

Also, really excellent points about the SEO aspect. The main reason behind wanting to remove stop words was more so for the benefits that come along with having shorter URLs. All though, in the StackOverflow question that Pete referenced, I thought the following was a really good point:

"Keep them in your URL. Even though Google may ignore them in normal search they do not when someone does an exact match search (i.e. using quotes)."

It's so worthwhile posting questions on this forum, because I always walk away with way more knowledge about PW than I expected. Thank you everyone :biggrin:

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...