Since wp_title() is usually called from the header.php file of your theme, then it runs on every page of your WordPress (frontend usually). So place the filter hook and function in your theme’s functions.php file, and just check if it’s a blog post before you change the title. Something like this:
add_filter('wp_title', 'filter_pagetitle');
function filter_pagetitle($title) {
//check if its a blog post
if (!is_single())
return $title;
//if you get here then its a blog post so change the title
global $wp_query;
if (isset($wp_query->post->post_title)){
return $wp_query->post->post_title;
}
//if wordpress can't find the title return the default
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
- Can’t change the title tag with 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 to filter users on admin users page by custom meta field?
- Passing Additional Parameters to add_filter Callable
- How can I add an Author filter to the Media Library?
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Change upload directory on custom plugin page
- How to use the_excerpt in a filter hook?
- Add wrapper to only youtube videos via embed_oembed_html filter function
- Hook into admin post list page
- How to change wordpress post title?
- Add post/page ID to inserted links within the_content
- How to exclude/filter a tag from get_the_tag_list()
- Shortcodes not resolved in AJAX call response
- Possible to filter the posts or categories that XML-RPC users see in their mobile application?
- Ajax, filters and shortcodes
- Filter the blog’s title without using global variables
- wp_link_pages output appears twice
- Multiple Ajax Data Action
- How to link current user to their author page through shortcodes
- Taxonomy Custom Column – ‘manage_{TAXONOMY}_custom_column’ filter only passing 2 arguments
- Filter Gutenberg Blocks Content
- Can you use add_filter() inside other function?
- How do I replace a render_callback function for a block?
- check if FILTER(“the_content”) is being executed in `the_post()`
- Change Password Strength Indicator names?
- Filter my args by the post 1st letter
- Limit RSS feed to previous calendar month
- Adding Filter to Homepage only
- How to modify core when there is no hook?
- Is this the proper way of switching the “Edit My Profile” link with my BuddyPress “Extended Profile” link?
- Does auto_update_plugin Filter Work When Put In Theme’s functions.php File
- In need of a content replace filter for posts in a specific wordpress category
- How to remove action with slashes and arrows?
- Inline Styles on all native blocks
- How to filter post content and force every link () made in blocks to return urldecode() with readable value?
- Get .subsubsub count of post per status queried using pre_get_posts
- Changing WordPress core without hacking core
- Link to Shop-Filter with .current-menu-item
- Plugin options, presets and filters : can you help me improve my workflow?
- Remove posts inside pre_get_posts using a custom query
- Remove / Hide Attachment Display Settings in Add Media popup / dialog
- how to customize rss feed tags using hooks?
- Wrapping my head around add_filter
- Is it possible to apply filter to meta key value when querying posts?
- How to add_filter to an OOP based apply_filter(‘foo::bar’, $a);
- apply_filters with multiple args and multiple add_filter
- Help with filter for wp_notify_moderator()
- Conflict calling an add_filter() twice
- Filter for author list in gutenberg core editor
- Add filter unless it is being called under specific function
- paginate_links() Change the order of links
- Filter / add_action to upgrade.php page
- Add Filter – Pass Variable (PHP < 5.3)
- Problem width wp_insert_post_data and Gutenberg block editor
- style_loader_tag not changing stylesheet to preload
- add_filter doesn’t return false?
- How to track a particular page in order to address the loading speed issue
- how to overwrite next_post_link
- Cutting off excerpt with first sentence
- Change URLs in default WordPress slider to relative from absolute
- Print url to default featured image
- What action/filter can be used for modifying the page to be rendered?
- Adding user filter – Not updating data in URL
- How to add more than one custom metadata as filter on the post list page?
- filter wptexturize doesn’t work on old posts titles
- remove_action conditionally for Custom Post Type – not working
- wp_get_attachment_link filter not working
- How would I remove an inline googleAPI font script in the the parent theme header.php?
- Getting entry ID from frm_email_message filter in formidable
- Is there a hook or filter that adds a button to the left of the search box?
- filter a list by gender
- How to elect position of new item output in a dropdown when using add_filter
- Filter a custom post type by custom field in admin
- Search and Filter Using Custom Post Type, Custom Taxonomy, and Advanced Custom Fields