WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/sanitize title with dashes

Contents

Description

Sanitizes title, replacing whitespace with dashes.

Limits the output to alphanumeric characters, underscore (_) and dash (-). Whitespace becomes a dash.

Note that it does not replace special accented characters (see plugins such as [1] to fix that).

Usage

<?php sanitize_title_with_dashes$title$unused$context 'display' ?>

Parameters

$title
(string) (required) The title to be sanitized.
Default: None
$unused
(string) (optional) Used to be the $raw_title, but is now unused.
Default: None
$context
(string) (optional) The context for the sanitation. When set to 'save', additional entities are converted to hyphens or stripped entirely.
Default: 'display'

Return Values

(string) 
The sanitized title.

Examples

Default usage

<?php
echo sanitize_title_with_dashes("I'm in LOVE with WordPress!!!1");
// this will print: im-in-love-with-wordpress1
?>

Notes

Does not apply the sanitize_title filter to the title.

Change Log

Since: 1.2.0

Source File

sanitize_title_with_dashes() is located in wp-includes/formatting.php.

Related

Functions

sanitize_title_with_dashes() is in a class of functions that help you sanitize potentially unsafe data which allow you to pass an arbitrary variable and receive the clean version based on data type. Others include:

Filters