How to modify title tag in a plugin?

What I actually ended up doing was to use filter document_title_parts. https://developer.wordpress.org/reference/hooks/document_title_parts/ I just unshifted a value to the array. I don’t think the documentation actually is very clear about that. And this method still don’t work with Yoast SEO installed.

How can I use a specific wordpress page template if certain words are used in page title [closed]

You can adjust the template to use in the fly based on the type of page you’re viewing. https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include add_filter( ‘template_include’, ‘portfolio_page_template’, 99 ); function portfolio_page_template( $template ) { if ( is_page( ‘portfolio’ ) ) { $new_template = locate_template( array( ‘portfolio-page-template.php’ ) ); if ( ” != $new_template ) { return $new_template ; } } … Read more

What change does this code need to include title of parent?

You can get all parent post id by get_post_ancestors function. add_filter( ‘document_title_parts’, ‘change_wp_title’, 20, 1 ); function change_wp_title( $title ) { global $post, $paged; $grappig = $title; // 404 if ( is_404() ) { $title[‘title’] = ‘file not available’; } elseif ( is_singular( ‘schedule’ ) ) { // get all parent post’s id $parents = … Read more

get_the_archive_title hook unwanted changes!

You could do something like this to see where it was called from: add_filter(“get_the_archive_title”, function($val) { $backtrace = debug_backtrace(); foreach($backtrace as $level) { if(array_key_exists(“file”, $level) && preg_match(“!that-file\.php$!”, $level[“file”]) && array_key_exists(“function”, $level) && $level[“function”] == “get_the_archive_title” ) { return “works: $val”; } } return “test: $val”; }, 10, 1); You’ll have to adapt the regexp (“that-file.php”) … Read more

Use WP Title instead of custom field to call

You’re passing too many arguments to urlencode. WordPress provides a couple of useful functions for these situations. add_query_arg is a helper to build a URL with query arguments, and esc_url provide sanitation and validations relevant to encoding URLs. Also, wp_title will display or return a combination of the page/post title and a seperator, which doesn’t … Read more