Get wp_title() from page ID into a variable

As you said, wp_title works only for current post, so can be a little tricky save it in a variable for a post that is not the current. However, wp_title works not only for singular post / page / cpt but also for every type of archive. So it’s easy create a custom function that … Read more

WordPress page title repeated in SOME pages

In order to play nicely with Plugins or other code that attempts to modify the HTML document title content (i.e. wp_title() output), you should always and only output this: <title><?php wp_title( ” ); ?></title> …and if you want to modify that output yourself, filter wp_title instead of hard-coding anything inside the <title></title> tags. So for … Read more

Add specific word before the category page title

Since WP 4.4 you can change document title using document_title_parts filter hook, in earlier versions it will be wp_title_parts (since v4.0) or wp_title filter. add_filter( ‘document_title_parts’, ‘se333744_site_title’ ); function se333744_site_title( $title ) { if ( isset($title[‘title’]) && strlen($title[‘title’]) && !is_front_page() && is_archive() ) $title[‘title’] = ‘ {some prefix} ‘ . $title[‘title’]; return $title; }

Include category title in wp_title

Create a helper function to get all parent categories (each post can be in multiple categories): function parent_cat_names( $sep = ‘|’ ) { if ( ! is_single() or array() === $categories = get_the_category() ) return ”; $parents = array (); foreach ( $categories as $category ) { $parent = end( get_ancestors( $category->term_id, ‘category’ ) ); … Read more

How to set custom title of custom page template?

Reference Got success by adding this code to your-page-template.php file before get_header() function: function my_page_title() { return ‘Your value is ‘; // add dynamic content to this title (if needed) } add_action( ‘pre_get_document_title’, ‘my_page_title’ );

REQUIRED: The theme must not used the tags. | REQUIRED: The theme must not call to wp_title()

WordPress added support for the title-tag feature in version 4.1 and it’s now a required feature for themes uploaded to the repo. To implement this feature, make sure your theme does not have the title tag hard coded within header.php, e.g.: <title><?php wp_title( ‘|’, true, ‘right’ ); ?></title> Configure your theme with title-tag support like … Read more

How to insert the number of posts from the category in wp _title?

If your theme supports WordPress adding the title tag using add_theme_support( ‘title-tag’ ); (it should!) you can use the document_title_parts filter to insert the post count in the right place without needing to parse the full title or modify existing elements that might have been customised, such as the separator: function wpse_323260_document_title_category_count( $title ) { … Read more

How to change the seperator in the title

UPDATE for WordPress 4.4 Since WordPress 4.4 the wp_title filter doesn’t work because wp_title() function is not used in core anymore. That function was marked as deprecated, then reinstated until new notice but theme authors are discouraged from using it. Because of that, wp_title filter still will work if you continue using wp_title() function directly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)