sanitize_title( string $title, string $fallback_title = '', string $context = 'save' ): string
- Since
- 1.0.0
- Source
wp-includes/formatting.php:2228
Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
Description
By default, converts accent characters to ASCII characters and further limits the output to alphanumeric characters, underscore (_) and dash (-) through the 'sanitize_title' filter. If
$title is empty and $fallback_title is set, the latter will be used.Parameters
$titlestring- The string to be sanitized.
$fallback_titlestringoptional- A title to use if $title is empty. Default empty.Default:
'' $contextstringoptional- The operation for which the string is sanitized. When set to 'save', the string runs through remove_accents(). Default 'save'.Default:
'save'
Return
string- The sanitized string.
Hooks fired · 1
One hook fires while sanitize_title() runs, in this order:
Uses · 2
- remove_accents()Converts all accent characters to ASCII characters.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 50
- WP_Admin_Bar::add_node()Adds a node to the menu.
- WP_Customize_Manager::import_theme_starter_content()Imports theme starter content into the customized state.
- WP_Customize_Manager::prepare_starter_content_attachments()Prepares starter content attachments.
- WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menu_object()Filters the wp_get_nav_menu_object() result to supply the previewed menu object.
- WP_Customize_Nav_Menu_Setting::filter_wp_get_nav_menus()Filters the wp_get_nav_menus() result to ensure the inserted menu object is included, and the deleted one is removed.
- WP_Customize_Nav_Menus::insert_auto_draft_post()Adds a new `auto-draft` post.
- WP_Font_Collection::__construct()WP_Font_Collection constructor.
- WP_Font_Collection::get_sanitization_schema()Retrieves the font collection sanitization schema.
- WP_Plugins_List_Table::single_row()Generates the markup for a single plugin row.
- WP_REST_Attachments_Controller::insert_attachment()Inserts the attachment post in the database. Does not update the attachment meta.
- WP_REST_Controller::sanitize_slug()Sanitizes the slug value.
- WP_REST_Font_Faces_Controller::prepare_item_for_database()Prepares a single font face post for creation.
Show all 50
- WP_REST_Font_Families_Controller::prepare_item_for_database()Prepares a single font family post for create or update.
- WP_Theme_JSON::compute_spacing_sizes()Generates a set of spacing sizes by starting with a medium size and applying an operator with an increment value to generate the rest of the sizes outward from the medium size. The medium slug is '50' with the rest of the slugs being 10 apart. The generated names use t-shirt sizing.
- _load_remote_block_patterns()Register Core's official patterns from wordpress.org/patterns.
- _load_remote_featured_patterns()Register `Featured` (category) patterns from wordpress.org/patterns.
- _register_remote_theme_patterns()Registers patterns from Pattern Directory provided by a theme's `theme.json` file.
- _wp_ajax_add_hierarchical_term()Handles adding a hierarchical term via AJAX.
- add_menu_page()Adds a top-level menu page.
- build_template_part_block_instance_variations()Returns an array of instance variation objects for the template part block
- dynamic_sidebar()Displays dynamic sidebar.
- get_category_by_path()Retrieves a category based on URL containing the category slug.
- get_sample_permalink()Returns a sample permalink based on the post name.
- is_active_sidebar()Determines whether a sidebar contains widgets.
- list_core_update()Lists available core updates.
- make_site_theme()Creates a site theme.
- media_handle_sideload()Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
- media_handle_upload()Saves a file submitted from a POST request and create an attachment post for it.
- permalink_anchor()Displays the permalink anchor for the current post.
- register_sidebar_widget()Register widget for sidebar with backward compatibility.
- register_taxonomy()Creates or modifies a taxonomy object.
- register_widget_control()Registers widget control callback for customizing options.
- render_block_core_latest_posts()Renders the `core/latest-posts` block on server.
- render_block_core_post_template()Renders the `core/post-template` block on the server.
- sanitize_title_for_query()Sanitizes a title with the 'query' context.
- term_exists()Determines whether a taxonomy term exists.
- update_nag()Returns core update notification message.
- upgrade_100()Execute changes made in WordPress 1.0.
- upgrade_110()Execute changes made in WordPress 1.2.
- upgrade_230()Execute changes made in WordPress 2.3.
- upgrade_330()Execute changes made in WordPress 3.3.
- wp_ajax_add_link_category()Handles adding a link category via AJAX.
- wp_get_custom_css_post()Fetches the `custom_css` post for a given theme.
- wp_insert_post()Inserts or updates a post in the database.
- wp_insert_term()Adds a new term to the database.
- wp_insert_user()Inserts a user into the database.
- wp_install_defaults()Creates the initial content for a newly-installed site.
- wp_install_maybe_enable_pretty_permalinks()Maybe enable pretty permalinks on installation.
- wp_render_layout_support_flag()Renders the layout config to the block wrapper.
- wp_update_custom_css_post()Updates the `custom_css` post for a given theme.
Source
function sanitize_title( $title, $fallback_title = '', $context = 'save' ) { $raw_title = $title; if ( 'save' === $context ) { $title = remove_accents( $title ); } /** * Filters a sanitized title string. * * @since 1.2.0 * * @param string $title Sanitized title. * @param string $raw_title The title prior to sanitization. * @param string $context The context for which the title is being sanitized. */ $title = apply_filters( 'sanitize_title', $title, $raw_title, $context ); if ( '' === $title || false === $title ) { $title = $fallback_title; } return $title;}History
Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.