Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing document_title_separator filter? #6400

Open
petenelson opened this issue Jan 9, 2017 · 1 comment
Open

Missing document_title_separator filter? #6400

petenelson opened this issue Jan 9, 2017 · 1 comment

Comments

@petenelson
Copy link
Contributor

While working on a client site, I needed to implement a custom title tag for a page that has content that comes from an API (i.e. not a single post, archive, author, etc). Part of this implementation was creating the <title> tag for the header. Because of this, we implemented filters for the various WPSEO functions (meta, title tag, etc). While working on the wpseo_title filter and reading through core, I see it's not using the document_title_separator filter that core uses in _wp_render_title_tag(). Core uses this to render a title if you have title-tag enabled for theme, and it calls wp_get_document_title() to generate the title.

WPSEO is using the pre_get_document_title filter to generate the document title, but if it's not being used, further down in the core code is this:

$sep = apply_filters( 'document_title_separator', '-' );

Since WPSEO doesn't tap into the document_title_separator hook, it looks like the only way to get the configured title separator is to call the utils method directly, so I ended up implementing this:

add_filter( 'wpseo_title', __NAMESPACE__ . '\title_tag' );

/**
 * Filter hook for the head title tag.
 *
 * @param  string $title The title.
 * @return string
 */
function title_tag( $title ) {

	// Get the page title (comes from term meta via a custom function).
	$title = title( '' );

	// Get the title separator from WPSEO, or via the standard filter
	// used by core.
	if ( class_exists( '\WPSEO_Utils' ) ) {
		$sep = \WPSEO_Utils::get_title_separator();
	} else {
		$sep = apply_filters( 'document_title_separator', '-' );
	}

	// Get the site name.
	$site = get_bloginfo( 'name', 'display' );

	// Return the title and site for the head title tag.
	return esc_html( sprintf( '%1$s %2$s %3$s', $title, $sep, $site ) );
}

Not sure if this was by design or an oversight, and I know this is likely an edge-case, but it might be good to have a document_title_separator in WPSEO that returns the WPSEO_Utils::get_title_separator() instead of need to call it directly.

Technical info

  • WordPress version: 4.6
  • Yoast SEO version: 3.9
@terw-dan
Copy link
Member

Thanks for your reply and feature request

Unfortunately we're not able to implement this at short notice. Currently we're focusing on issues that affect many users. We've concluded that this feature won't be used by many users, therefore we are not able to fix this short-term.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants