WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/sanitize title

Contents

Description

sanitize_title is a filter applied to a value to be cleaned up for use in a URL by the function sanitize_title().

Usage

function my_sanitize_title($title, $raw_title, $context) {
    # ...
}
add_filter('sanitize_title', 'my_sanitize_title', 10, 3);

Parameters

$title
(string) (required) The string to be sanitized.
Default: None
$raw_title
(string) (optional) The original string, before being sanitized by sanitize_title().
Default: None
$context
(string) (optional) The operation for which the string is sanitized.
Default: None

Examples

Require URL component be lower-cased:

add_filter('sanitize_title', 'strtolower');

Replace plusses with dashes:

function plush_to_dash($title) {
    return str_replace('+', '-', $title);
}
add_filter('sanitize_title', 'plus_to_dash');

Change Log

  • Since: 1.0.0
  • $raw_title parameter added in 2.8
  • $context parameter added in 3.1

Source Files

This filter is applied by:

Related

Functions

Filters

See also index of Function Reference and index of Template Tags.
This page is marked as incomplete. You can help Codex by expanding it.