• Hi

    How can I get read of the separator in wp_title()?

    If I use wp_title(”) (no space in between) it puts a space in as a separator anyway.

    Thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • What theme are you using and what’s the link to the blog? Looks like moshu is here now lol, maybe he’ll know right off the bat what you need done. =)

    Viper007Bond, hahaha..atleast there are some people here now with more “php” knowledge then me lmao! I’m not really that great with it…thanks for your reply, for him.. =)

    spencerp

    Hmm, wonder if this will work:

    wp_title('<!--blah-->')

    Thread Starter ChristopherO

    (@christophero)

    No, because surely that would still put a comment on the page, not a blank space.

    There seems to be one or two leading spaces regardless of the separator you specify in the tag. You can strip the opening spaces by using
    <?php trim(wp_title('')); ?> or if you want to have it not print out, you can do something like <?php $title=trim(wp_title('', false)); ?> and then you can use it elsewhere in PHP or echo the output.

    Good luck,
    Michael.

    EDIT: Just to clarify, the above will put out the post or page title, with no separator and no leading spaces.

    No, because surely that would still put a comment on the page, not a blank space.

    Yes, but HTML comments don’t show up, hence I’d think that that’d work.

    niziol: why trim?

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

    In part because I am especially retentive about some things, I should be a poster boy for OCD.

    The tag seems to leave some wayward spaces in the title tag, this is present on many blogs powered by WordPress – my first assumption is always “Michael, what did you screw up now?” so I looked at some other WP2+ powered blogs and it does exist in a majority of them. The ‘offending’ code is lines (I believe) 198-200 in template-functions-general.php, you can see that though you can select the separator via the tag, you can not select the spacing around that separator without hacking the code or trimming it, none that I have found at least. If there is an easier way around this, I’d be much obliged if you’d point it out for me!

    Though this seems to have no impact on how the title is display, I think it completely defeats the purpose of allowing a user to choose a separator, yet force a prefixed and affixed space around it. Not so much an issue if you use the example you’ve posted above, but some like to have <?php wp_title(''); bloginfo('name'); ?> which does leave the awry space preceding the title, ie: <title> title – blog</title>.

    Again, hardly a major issue, just a little ‘tip’ for anyone as obsessive as I am! ??

    Cheers,
    Michael

    mmm… why don’t you keep it simple and do this:

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

    That will output the post/page title no spaces, separators, nothing! And of course you will replace FOO with your own html separator.

    ??

    xmarcos: Because that would be the easy and smart thing for me to have done, had I even thought of it! I have no qualms with admiting that this is yet another example of how I can be a “himbo”!

    Thanks for the tip ??

    Thanks for the_title(); – it was the last piece in my reworked TITLE coding that was bothering me. The snippet below delivers one set of tags for the homepage, and SEO-optimized TITLEs for post pages (with the post name first, not bloginfo(’name’). Hope it helps someone!

    <title><?php if (is_home()) { ?><?php bloginfo('name'); ?> &raquo; Whateveryouwantgoeshere<?php } else { ?><?php the_title(); ?> &raquo; <?php bloginfo('name'); ?><?php } ?></title>

    Hi,

    I’m a total newbie on this but I think I’ve found a problem with this approach. When you use the_title() it will insert the title of the first post on a page for the categories whereas wp_title() appears to insert the correct title of the category.

    I could be completely wrong here btw!

    FB

    Just a follow up…

    I’ve now replaced the_title() with <?php trim(wp_title('')); ?> but the two spaces are still appearing as if the trim is doing nothing.

    FB

    Here’s the best answer i’ve found:

    https://elasticdog.com/2004/09/optimal-title/

    I’ve written some instructions for changing the behavior of wp_title to produce better page titles. This includes a method for removing the separator, as the original poster requested, and also for removing the unwanted spaces, per a later request.

    https://www.ardamis.com/2006/07/03/optimizing-the-syntax-in-the-wordpress-title-tag/

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘wp_title() removing separator’ is closed to new replies.