Forums

adjust wp_title to remove space (4 posts)

  1. escdotdot
    Member
    Posted 4 years ago #

    I know this may sound like a crazy request, but I just want to alter the output in the title tag so there is no space between the blog name and the title of the post. I have tried:

    <title><?php bloginfo('name'); ?><?php wp_title(''); ?></title>

    and although this removes the default &rquo; it leaves a space behind.

    Is there any way of getting rid of this space? Thanks.

  2. anotherword
    Member
    Posted 4 years ago #

    Give this a shot. Depending on your choice of meta title code, it will also remove the blank white space from the beginning of the page code title. So, instead of <title> Here's my page title</title>, you'll see <title>Here's my page title</title>. See code below. Hope it helps.

    trim(wp_title('', false))

    Maybe in your case, you could try this. I haven't verified/tested, but should work ok. Either way, the important piece of code is above.

    <title><?php bloginfo('name'); ?><?php trim(wp_title('', false)); ?></title>

  3. Austin Matzko
    Member
    Posted 4 years ago #

    anotherword's solution won't work, because wp_title prints its output before trim can trim it. Besides, the space is within the string.

    To trim out the separator and surrounding spaces, put the following in your theme's functions.php template file:

    add_filter('wp_title', create_function('$a, $b','return str_replace(" $b ","",$a);'), 10, 2);
  4. zompus
    Member
    Posted 4 years ago #

    Stick the following in your functions.php file, located within your theme folder.

    // Removes the white spaces from wp_title
    function af_titledespacer($title) {
    	return trim($title);
    }
    
    add_filter('wp_title', 'af_titledespacer');

    Hope that helps. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic