• Matt

    (@syntax53)


    If the site tagline/description is blank, SEO will rewrite the title as “Site Home | ” which looks rather dumb. The separator should be left off if the tagline/description is blank.

    I added the following function/filter to fix it for now:

    function asd_wp_title_filter ( $title, $sep='|', $seplocation='right' ) {
    	if (empty($sep)) return $title;
    	$title = trim($title);
    	if ($seplocation == 'right') {
    		if (substr($title, -1) == $sep) $title = trim(substr($title, 0, -1));
    	} elseif ($seplocation == 'left') {
    		if (substr($title, 0, 1) == $sep) $title = trim(substr($title, 1));
    	} else {
    		if (substr($title, -1) == $sep) $title = trim(substr($title, 0, -1));
    		if (substr($title, 0, 1) == $sep) $title = trim(substr($title, 1));
    	}
    	return $title;
    }
    add_filter( 'wp_title', 'asd_wp_title_filter', 15, 3 );
    add_filter( 'aioseop_title', 'asd_wp_title_filter' );

    edit: updated function for possible seplocation scenarios. untested though.
    https://wordpress.org/plugins/all-in-one-seo-pack/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Steve M

    (@wpsmort)

    Thanks for the suggestion Matt. We’ll review this and consider it for release in the next version.

    Hi Matt,

    I looked into this; because the separator is part of the title format in All in One SEO Pack, and because we can’t control what or which characters people might use in their title formats, I don’t think we can reasonably fix this in all cases. I’d instead suggest using a title format that doesn’t contain a site title and a pipe character for sites that don’t have site titles. Or keep using your fix, that should work fine as well.

    Thread Starter Matt

    (@syntax53)

    I don’t know if my workaround is throwing you off, but I only posted that as a workaround for others until something is changed in the meantime. It wasn’t to offer a fix for the problem.

    In aioseop_class.php you have this:

    function get_original_title( $sep = '|', $echo = false, $seplocation = '' ) {
    		global $aioseop_options;
    		if ( !empty( $aioseop_options['aiosp_use_original_title'] ) ) {
    			$has_filter = has_filter( 'wp_title', Array( $this, 'wp_title' ) );
    			if ( $has_filter !== false )
    				remove_filter( 'wp_title', Array( $this, 'wp_title' ), $has_filter );
    			if ( current_theme_supports( 'title-tag' ) ) {
    				$sep = '|';
    				$echo = false;
    				$seplocation = 'right';
    			}
    			$title = wp_title( $sep, $echo, $seplocation );
    			if ( $has_filter !== false )
    				add_filter( 'wp_title', Array( $this, 'wp_title' ), $has_filter );
    			if ( $title && ( $title = trim( $title ) ) )
    				return trim( $title );
    		}
    [...]

    I’m pretty sure–

    if ( current_theme_supports( 'title-tag' ) ) {
    	$sep = '|';
    	$echo = false;
    	$seplocation = 'right';
    }
    $title = wp_title( $sep, $echo, $seplocation );

    is what was causing my issue. And because you are removing previous filters, I had to filter on the only one you provide (“apply_filters( ‘aioseop_title’, $title );”) later.

    Thread Starter Matt

    (@syntax53)

    Actually I just checked and the theme on the site I was working with does not add support for title-tag. However, the default value of $sep for function get_original_title is “|” so it’s essentially the same.

    Thanks Matt, I’ll test this further. The code you mention is a workaround, and could probably use to be improved here. However, I’ll note that get_original_title() often won’t get called in the first place; it only gets called on our wp_title() filter if Rewrite Titles is turned off, or if All in One SEO Pack is unable to generate a title from the SEO settings. I’ll see if we can do a better job here of passing along parameters, and if that fixes this issue, for the next major release.

    Thread Starter Matt

    (@syntax53)

    This is what I know… by default the theme on this particular site (https://wordpress.org/themes/bouquet/) has this in the header.php:

    <title><?php wp_title( '|', true, 'right' ); ?></title>

    The ‘tagline’ is set to blank. And with AIO enabled, the title shows up as: “Title | “.

    Even if I change the header line to:

    <title><?php wp_title( ' ', true, 'right' ); ?></title> (which is not what I want, just an example) AIO SEO still overwrites it the same way. I have to apply the filter that I wrote in the first post in order to set it how I want it.

    Hi Matt,

    If you have Rewrite Titles on in All in One SEO Pack, then this should be using the title format for whatever type of page that page is. Is that the case, and could you give me a link to the page in question? The defaults for wp_title() shouldn’t matter in this case, as they are the same as the ones we are using.

    Thread Starter Matt

    (@syntax53)

    Rewrite titles is turned on. The homepage is set to a static page (the static page option is NOT turned on under “home page settings.” And the “Home Page Title Format” is set to “%page_title%” (default, I believe). If I change it to “%blog_title%” the problem goes away.

    Thread Starter Matt

    (@syntax53)

    I still say though that regardless of what the setting are, AIO SEO is the one setting the title, and it’s setting it in a way that should be avoided. No matter what settings I have, it should never put a separator in when there is nothing to separate. Plain and simple.

    Hi Matt,

    Thanks for clarifying this. If the homepage title format is just set to “%page_title%” then there should be no separator; I’ll see if I can reproduce this issue.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Title gets rewritten with blank seperator on home’ is closed to new replies.