use the wp_title filter. just remove all your code from header.php and put this into your plugin instead:
add_filter( 'wp_title', 'my_wp_title', 10, 2 );
function my_wp_title( $title, $sep = '|' ) {
if ( is_page( physician_single_pg() ) and get_query_var( 'doctor' ) ) {
$doctor = get_query_var( 'doctor' );
$title = ... // here you put your code to build your title from the doctor & hospital name
}
return $title;
}
add_filter( 'query_vars', 'my_query_vars' );
function my_query_vars( $vars ) {
$vars[] = 'doctor';
return $vars;
}
Related Posts:
- Changing title of a page dynamically from within a plugin
- Change language on website and change currency with url query
- Show a different number of posts per page depending on context (e.g., homepage, search, archive)
- Custom pages with plugin
- Add rewrite rule to permalink structure
- Add Rewrite Rule for custom page
- Is their any way to Extend WPDB class and Overwrite the Default Query Function
- add_rewrite_rule, plugin activation and plugin deactivation
- Using nextGen Gallery.. how can I call a list of all Gallery Names?
- Search and replace text across all posts
- Change page title from plugin
- What is the best way to output plugin result in certain url
- What is the proper filter to add html to a post / page title?
- How to add terms to a post depending on its title?
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Custom rewrite rule is not picked by WordPress
- Add .html extension to custom post type taxonomies
- bulk post_content update
- Woocommerce different URL for every table placed in the restaurant
- Author Specific URL’s in WordPress
- Does flush_rewrite_rules() remove all rules added by other plugins as well as mine?
- Add_rewrite_rule doesn’t add custom url in plugin
- Nested CPT URLs + Posts 2 Posts
- How can I rewrite a plugin generated URL?
- flush_rewrite_rules() not working on plugin activation
- [Plugin: Posts 2 Posts] How does it work?
- WordPress custom URL Rewrites redirecting not masking
- Capitalize All Titles and Headlines in Chicago Style
- custom taxonomy and custom post type url conflict
- Rewrite url without flushing the database?
- How can I list recent posts excerpts?
- Post query – show posts from specified day and month and whole years
- WordPress URL redirect
- Best way to hook a custom url?
- Checking that the Rewrite API is available
- How does WP handle multiple matching rewrite rules?
- How to Create a Custom Plugin Permalink
- Why slash is removed after domain?
- Plugin echos text from shortcode function in gutenberg page editor
- Events Made Easy Plugin – Duplicate Title Tags
- How to append to title via functions.php for auto-posting plugin [duplicate]
- how to change the verification url of pie register plugin of wordpress?
- Plugin appends ugly URL string to index
- Custom rewrite rules not working with WPML
- Rewrite rule not matching
- WP Query. Is there a maximum size?
- WordPress and a secondary database?
- Which filter affects the ‘entry-title’ post class
- How to Create a Custom Slug for Tags and Categories with a prefix or suffix?
- how to add text to posts from tags
- URL rewrite of independent plugin?
- Plugin generated taxonomies’ permalinks with custom placeholders
- plugin code is pulling information from database in one instance and not in other. What is wrong?
- WooCommerce search products between price range using WP_Query
- Show Sitename on Yoast SEO Title tag [closed]
- correct validate and sql query
- correct sql query
- SQL query, error
- Modify page title and subtitle with a plugin
- Create a post builder skin in a plugin
- Locked out of admin panel after installing HC Custom WP-Admin URL [closed]
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Insert Message before content of after title
- Custom url rewriting
- Taxonomy Drill-Down / Plugin Help – hierarchical queries within plugin?
- WordPress plugin url for form submit
- Creating author Specific page URL
- Customizing Titles on the Fly with Code
- What is the best way to cache pages on WordPress
- Always get creating a new table with foreign key
- problem with sql query
- add_query_arg not work in admin
- URL rewrite with external JSON query
- How to return the values from a row where a value occurs for the first time among the rows available?
- Site shows URL instead of “meta title” after deleted few plugins (not any SEO plugin was deleted)
- Username Variable in custom links?
- How to use apply_filters?
- WordPress rewrite rules not working
- How to rewrite URL and get the values?
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- If post exists in the database – each time goes on `else`
- How to force load a page in plugin?
- How to embed a new string in url?
- i want to rewrite my custom plugin url
- rewrite file to wordpress
- TranslatePress | secondary language category/sub-category not working correctly “`/%category%/%postname%/“`
- Dynamic URL Rewrite for Custom
- How to search post titles with whole words only, but not the exact word only?
- add_rewrite_rule to load different page, without changing URL in browser
- Hidden permalink different from displayed permalink
- Having a problem with rewrite_rules and rewrite_tags – url not rewriting properly and query var missing
- Displaying different content depending on variable
- How to create algorithm for ordering posts in WordPress?
- WordPress rewrite rule depend on meta values not ids
- Custom Rewrite Rule Removing Query String
- one url for all pages
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- Change custom rewrite rule when permalink is updated/changed
- How to give .html extension to just one post not all post
- URL Rewrite 404