Add dynamic info to the Wordpress Title Tag

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

Since the change to WP 4.1 they use the add_theme_support( 'title-tag' ); to allow wordpress to handle the title tag. Most of the time this is fine but I came across an instance where I need to edit it.

I've created a simple page and by using an api I'm dynamically changing the content on it. But when it comes to SEO they all have the same page title. Example: http://vitaferm.com/product/?id=372

Is there a way for me to add my product titles to the page title with the way WP is configured or is the solution to remove the theme support in the functions.php and then hard code it into the header.php.

I just wanted to double check that I wasn't missing something with how it is currently configured before I remove the theme support. It will always be a pain in the ass every time we have an upgrade.

回答1:

I found the solution here https://www.developersq.com/change-page-post-title-wordpress-4-4/

add_filter('document_title_parts', 'dq_override_post_title', 10); function dq_override_post_title($title){    // change title for singular blog post     if( is_singular( 'post' ) ){          // change title parts here         $title['title'] = 'EXAMPLE';      $title['page'] = '2'; // optional     $title['tagline'] = 'Home Of Genesis Themes'; // optional         $title['site'] = 'DevelopersQ'; //optional     }      return $title;  } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!