Forums

[resolved] Multi-Word Tags? (17 posts)

  1. kane250
    Member
    Posted 3 years ago #

    Hi,

    I don't use WordPress often but am building a site on it now. I am trying to use tags that are more than 1 word to group together similar content on my site, but the only ones that work are one word tags. Is this the case? I notice that when a multi-word tag is used, it enters the tag name in the browser like this: tag%20example (tag example). However even if I switch the tag to exactly that, with the %20, it still does not work. Anyone know why this might be happening?

    Thanks in advance!

  2. kane250
    Member
    Posted 3 years ago #

    Anyone?

  3. webjunk
    Member
    Posted 3 years ago #

    I think maybe you lost people. I use multi-word tags without a problem. The "20%" is browser related 20% = space so if you had a URL with a space, maybe a directory called "just a directory" like:
    yoursite.com/just a directory
    in most browsers it would become
    yoursite.com/just20%a20%directory

    Where are you entering the tags and how exactly?

  4. kane250
    Member
    Posted 3 years ago #

    Hi, thanks. Basically I am modifying a theme for someone. They wanted to have the titles of their posts actually be tags since many of their posts share the same title, so I reprogrammed it so that whatever the word or words are in the title, actually link to a tag. Additionally, each post is actually tagged with that same word or words. So they call: ?tag=just a directory, which in the URL turns into /?tag=just%20a%20directory. The end result is that it doesn't work. It works with all one word titles, but nothing with a space...

    any ideas?

  5. webjunk
    Member
    Posted 3 years ago #

    Might want to try using "%2b" instead of the "%20" That inserts a "+" sign which you could try also. Let me know if that works. Some things need it that way to group word objects.

  6. kane250
    Member
    Posted 3 years ago #

    Well that didn't work much either, but I did use php str_replace and replace all the spaces with underscores, which fixed 99% of them when I retagged them with underscored tags..however now I have a few with apostrophe's...any idea on this one?

    ex: tag's should be tags but str_replace isn't doing it for this one...

  7. asechrest
    Member
    Posted 3 years ago #

    What's the code you're using to try to strip the apostrophe?

    str_replace("'", "", $string);

  8. Mark / t31os
    Moderator
    Posted 3 years ago #

    Tags are intended to be single words from what i understand..

    Not all browsers will understand spaces in file or url names, so you should avoid them or replace them, which it looks like you're doing.

    Could we see your code ?.. As asechrest asked.. :)

  9. kane250
    Member
    Posted 3 years ago #

    This is the entire chunk I am using right now which only adds the underscore to it. I'd like to have it change spaces to underscores as well as check for apostrophes and remove them. I made an attempt at this and it didn't work.

    <h2><?php $title = get_the_title(); ?> <a href="?tag=<?php echo str_replace(" ", "_", $title); ?>"><?php echo $title; ?></a></h2>

  10. Mark / t31os
    Moderator
    Posted 3 years ago #

    So this doesn't work?

    <?php
    $title = get_the_title();
    $title = str_replace(" ", "_", $title);
    $title = str_replace("'", "", $title);
    ?>
    <h2><a href="?tag=<?php echo $title; ?>"><?php echo $title; ?></a></h2>
  11. kane250
    Member
    Posted 3 years ago #

    Right, this wont work for some reason. I tried it this way as well as making a dual str_replace with arrays... It's being very difficult...

  12. Mark / t31os
    Moderator
    Posted 3 years ago #

    Above works in my test file...

    Contents of test file..

    <?php
    $mystring = "some string with lots of ''''''apostrophes";
    $mystring = str_replace(" ","_", $mystring);
    $mystring = str_replace("'","", $mystring);
    echo $mystring;
    ?>

    Output is..
    some_string_with_lots_of_apostrophes

  13. kane250
    Member
    Posted 3 years ago #

    Right, in theory it should be fine, right? Here is how I am using what you just showed me:

    <?php $title = get_the_title(); $title_link = str_replace(" ", "_", $title); $title_link2 = str_replace("'", "", $title_link); ?>
    				<h2><a href="?tag=<?php echo $title_link2; ?>"><?php echo $title; ?></a></h2>

    I don't want the actual title being shown to have the underscores and apostrophes, so I'm using different variables...but for some reason when it runs, it only still adds the underscores, and leave's the apostrophes.

    If $title was: The Maker's
    the output would be: The_Maker's

    I have no idea why this wouldn't work...

  14. kane250
    Member
    Posted 3 years ago #

    wow I also just noticed that wordpress adds apostrophes automatically to my tags. WTF? It won't allow me to remove an apostrophe from the tag in the post area. Is this standard?

    EDIT - I was able to remove the apostrophe in the tag area...so omit this last rant, but the same problem still persists anyway.

    If I manually call the tag in my url without the apostrophe, everything works great but it's as if WordPress is refusing to let PHP remove an apostrophe in the title link.

  15. sdrib
    Member
    Posted 2 years ago #

    Hi!

    I am kinda experiencing a similar problem here.

    I am using "the_tile()" to define the names of images

    so if my title is "tileA" my images name will be "imageA.jpg"

    now the problem is that some of my titles contain question marks
    which won't work in image names, so i want to strip those out of there for that reason.

    I used str_replace

    <?php $title = the_title(); $title = str_replace ("?", "", $title);?>

    and

    <?php echo $title; ?>

    later on to recall but i get no results the titles come back out the same way is they got in

    what m i doing wrong?

    thanks a lot :)

  16. sdrib
    Member
    Posted 2 years ago #

    oh it works with get_the_title i overlooked that before

    <?php $title = str_replace ("?", "", get_the_title());?>
    <?php echo $title; ?>
  17. Mark / t31os
    Moderator
    Posted 2 years ago #

    Yes that's because the_title() echoes it's result by default, when you're taking the value to use in a variable you need it to return not echo.

    You can also use the_title('','',false); which simply tells the_title to return instead echo... :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.