Questions tagged [slug]

part of a URL that makes it more human readable or SEO-friendly, but without necessarily being required by the web server.

A slug is a part of a URL that makes it more human readable or SEO-friendly, but without necessarily being required by the web server. Slugs can be generated from a page title and are typically the last part of the url.

Example:

  • Page Title: c# - What's the difference between String and string? - Stack Overflow
  • Slug: whats-the-difference-between-string-and-string

The full URL including the slug is https://stackoverflow.com/questions/7074/whats-the-difference-between-string-and-string. Note that punctuation in the url is typically removed.

1272 questions
8
votes
7 answers

T-SQL function for generating slugs?

Quick check to see if anyone has or knows of a T-SQL function capable of generating slugs from a given nvarchar input. i.e; "Hello World" > "hello-world" "This is a test" > "this-is-a-test" I have a C# function that I normally use for these…
Jeremy Cade
  • 1,351
  • 2
  • 17
  • 28
8
votes
6 answers

Creating Slugs from Titles?

I have everything in place to create slugs from titles, but there is one issue. My RegEx replaces spaces with hyphens. But when a user types "Hi     there" (multiple spaces) the slug ends up as "Hi-----there". When really it should be…
James Jeffery
  • 3,365
  • 4
  • 19
  • 13
8
votes
2 answers

Displaying both slug and ID in URL, but route by ID only in Django

What I'm trying to achieve is: my News app should display a slug, but only query the article by ID in the form of /news/24/this-is-the-slug Unfortunately I'm getting a NoReverseMatch: Reverse for 'news_detail' with arguments '('',)' and keyword…
weeheavy
  • 253
  • 3
  • 18
8
votes
8 answers

creating unique page title slugs php

I have a function for creating unique slug for a page title. It checks if the slug is available in the pages table then creates a unique slug by adding a '-int' accordingly. The function works fine for the first three entries eg for 'test slug'…
bStaq
  • 121
  • 1
  • 2
  • 7
8
votes
1 answer

Symfony 2 - Sluggable not set when using form

I am trying to use the Sluggable behaviour from the Doctrine Extensions bundle: http://gediminasm.org/article/sluggable-behavior-extension-for-doctrine-2 I have set up a sluggable field in my entity using annotation but the value does not get set…
Dan
  • 6,265
  • 8
  • 40
  • 56
7
votes
1 answer

MySQL Insert row, on duplicate: add suffix and re-insert

My question is rather complex, but I thought I should give it a try. In short, I want to insert a row with a slug (short string with alphas and a dash: this-is-a-slug). The problem is that slug is a unique key and there might be duplicates. When…
Tony Bogdanov
  • 7,436
  • 10
  • 49
  • 80
7
votes
1 answer

What is the best way to clean a string for placement in a URL, like the question name on SO?

I'm looking to create a URL string like the one SO uses for the links to the questions. I am not looking at rewriting the url (mod_rewrite). I am looking at generating the link on the page. Example: The question name is: Is it better to use…
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
7
votes
1 answer

Custom Post Type Slug clash

I have multiple custom post types with custom taxonomies. I'm having a slug clash despite of having different parents. Here is my URL structure: /work/%client_name%/%project_name% I have a client (client1) and project (some-cool-project-name) that…
ialphan
  • 1,241
  • 1
  • 17
  • 30
7
votes
4 answers

What is the best way to store a unique URL Slug?

I'm trying to generate some url 'slugs' for my website. It's based upon a single piece of user generated text. Now, i have made my own slug method, so i'm not after some code for that. What i'm wondering is where is the best place to determine if…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
7
votes
1 answer

Cleaning form data in Django

How can i clean and modify data from a form in django. I would like to define it on a per field basis for each model, much like using ModelForms. What I want to achieve is automatically remove leading and trailing spaces from defined fields, or turn…
Josh Hunt
  • 14,225
  • 26
  • 79
  • 98
7
votes
3 answers

Using slugs in laravel 5?

I have made eloquent-sluggable work on my app. Slugs are saved just fine. Buuuut... How do I use it to create a pretty url? If possible, I would like to use them in my url instead of ID numbers.
MartinJH
  • 2,590
  • 5
  • 36
  • 49
7
votes
5 answers

Limiting returned wordpress fields from WP_Query or 'get' functions

Looking to limit the returned fields of a WP Query to help with speeding up the response from the server and reducing the amount of data retrieved. For the query I'm using, it only needs up to 3 fields of data, the rest is brought in through ACF…
sneexz
  • 265
  • 2
  • 4
  • 10
7
votes
6 answers

slug field on flask

I want to create a slug field stored in database. I searched and I found http://flask.pocoo.org/snippets/5/ but I'm having trouble integrating the code in my app. This is my modele.py: from unicodedata import normalize def slugfy(text,…
anouar
  • 125
  • 1
  • 1
  • 10
7
votes
4 answers

Make a post slug unique

I got few functions in placed which is not working as I wanted. The slug is automicatlly created on the fly depend on the post title. Example: If a post title is "test" then the slug will be "test" My problem is that, what if theirs duplicate…
Johny
  • 401
  • 1
  • 6
  • 14
7
votes
3 answers

How can I create slugify in symfony2?

I have started to use symfony2 and I have found some functions that exists in symfony 1.4 like slugify. I need this in order to improve the furl.
gastonnina
  • 559
  • 1
  • 10
  • 23