When adding title-tag
support in a theme, the title tag can be filtered by several filters, but not wp_title
. The reason is that if the theme supports title-tag
, WordPress uses wp_get_document_title()
instead of wp_title()
.
For themes with support for title-tag
you can use document_title_parts
:
add_filter( 'document_title_parts', 'filter_document_title_parts' );
function filter_document_title_parts( $title_parts ) {
$title_parts['title'] = 'The title';
$title_parts['tagline'] = 'A tagline';
$title_parts['site'] = 'My Site';
return $title_parts;
}
add_filter( 'pre_get_document_title', 'filter_document_title' );
function filter_document_title( $title ) {
$title="The title";
return $title;
}
Related Posts:
- Remove description from on Home
- Filter Widget Title Wrap
- Don’t replace “|” with Empty String (“”) when generating slugs from title
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- Alter only the page title, not the post titles within
- Changing document title only on a custom page template
- Filtering ‘the_title’ with option to return subhead?
- wp_title() empty on a static front page
- Setting title using wp_title filter
- Add a Span Around a Product Title in WooCommerce [closed]
- Wrap h1-h6 in a div
- Variables in post title
- Is it possible to use multiple spaces in title?
- WP action/filter to modify title before header output and article output?
- Filter media upload attachment meta
- Use of comment_reply_link_args filter
- Filter page title (displayed in browser tab) of wp-login
- Strip $before & $after strings from a page title
- add_filter( ‘the_title’ gets through this if statement twice
- Filter Post Title without affecting screen-reader-text
- Modify WordPress Page Title ()
- How to filter page title for certain page?
- get_the_archive_title hook unwanted changes!
- Hide H1 Title using the_title filter
- Admin filter/error if post title is too long
- Auto append text after the title?
- How do filters and hooks really work in PHP
- Trouble understanding apply_filters()
- How would one modify the filtering Gutenberg applies to pasted content?
- Gutenberg: Is there a way to know if current block is inside InnerBlocks?
- How to reorder billing fields in WooCommerce Checkout template? [closed]
- WordPress Internal @ Mentions
- Filter translations (gettext strings) on specific admin pages
- Is it possible to use object in add_action?
- Filter hook before create order WooCommerce
- Add Class to Specific Paragraph of the_content()
- apply_filters() slices away needed arguments
- How to override the email function by using filters? [closed]
- Remove WPML’s home_url filter
- Filter the blog title displayed in the header
- PHP5, Inheritance, Singleton – action & filter hook limitations
- How can I register a new REST context?
- How can I add a fifth option to the alignment picker?
- How to stop WordPress from changing ellipsis into a pre-composed triple-dot glyph?
- Right way to add HTML bloginfo name using a filter
- Allow EPS file upload – two EPS files have different MIME types
- How to call a function or method that is Namespaced using another plugin
- How to change currency programmatically on creating order action?
- Applying custom filter instead of the_content doesn’t render embeds
- Change username before login
- Replace a word with a word in the URL string
- Remove Actions added by SEO ultimate Plugin
- Modifying a CoBlocks Filter in Functions
- Shortcodes — Using add_action, add_filter in the shortcode
- Remove Content Filter
- views_edit-post filter not working (custom post type)
- How to know what filter to use and how to use it?
- Replace audio links with jplayer using the_content filter
- Sorting a specific taxonomy by archive date using URL
- Give “Read More” precedence over excerpt() word count
- Adding a filter to comments_template
- How to customize category_description()?
- Add Bootstrap Classes to Recent Posts Widget
- Add filter to get_posts
- Is it possible to override the default Gallery Settings form?
- Filtering a list of objects with ‘OR’ on the same field
- Excerpt is being added above the content, but it should be after it
- WordPress add script with custom type (x-jquery-tmpl)
- How to filter bbPress replies (content)?
- Change login CSS
- How to redirect non-logged in users to login with post_password_required()
- How to add nonce tag to inline script for CSP
- Change user nicename without sanitize
- How to override include_once pointed file using add_filter?
- How to strip out javascript in wp_posts `post_content`
- Register new user, assign custom role then send email
- How can I get the default content of WordPress post?
- How do I hide tinymce within the edit screen of a particular page
- What would cause the gettext filter to not work for a given text domain?
- pre_get_posts to hide everywhere posts from “Archive” category
- How to remove shortcode(s) from WYSIWYG Page editor for Non Admins
- What is the action or filter for adding information under the Permalink in Edit Post/Page?
- Shortcode / plugin with custom (flexible) output
- Adding a filter to related posts not working
- add_action with associative array
- Why does wp_die() not work when inside a namespace?
- Remove image of srcset
- Modify wp headers on specific page
- Set post featured image to author image
- How to make the show as a button?
- Take filter from multiple functions
- Read More in the actual excerpt
- WP REST API v2. filters doesn’t work
- Is it possible to include the add_filter() function within a shortcode function
- filter on the_content stopped working when I updated to WP 3.6.1
- Replace Paid Shipping Method With Free Shipping Method WooCommerce [duplicate]
- Clean/filter HTML inserted to post content by XML RPC
- Is it possible to make get variable out of filter in Class?
- NextGEN Gallery: Adding drop-down menu widget to gallery view without modifying plugin code [closed]
- Limit total tags in the_content