WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Encoding of apostrophes via the_title / get_the_title (4 posts)

  1. C W
    Member
    Posted 2 years ago #

    I've been trying to create a custom Twitter button for a news website, but am having difficulties retrieving post titles. Perhaps the easiest way to describe the issue is just to show it: if you go to this page and try to use the Tweet button, you'll see that the title outputs as "Ratings: Cadel Evans%E2%80%99 Tour de France victory sends SBS soaring" instead of using the apostrophe.

    At the moment I'm using str_replace to turn "%20" into "+" signs which ensures that spaces turn out correctly:

    function the_titlestring() {
    $titlestring = get_the_title($post->ID);
    $titlestringprocessed = str_replace( " ", "+", $titlestring );
    echo $titlestringprocessed;
    }

    ... but I can't work out how to do the same thing with apostrophes and quotation marks. Is there a simple way to convert output from get_the_title() into the proper form?

  2. nsathees
    Member
    Posted 2 years ago #

    use url_encode > a php class to handle URL's

  3. C W
    Member
    Posted 2 years ago #

    I'm probably making a very basic mistake somewhere, but using urlencode seems to make things worse: instead of outputting "Ratings: Cadel Evans%E2%80%99 Tour de France victory sends SBS soaring", it's now outputting "Ratings%3A Cadel Evans%26%238217%3B Tour de France victory sends SBS soaring".

    function the_titlestring() {
    $titlestringprocessed = urlencode(get_the_title($post->ID));
    echo $titlestringprocessed;
    }
  4. C W
    Member
    Posted 2 years ago #

    Doesn't matter, found a workaround. Thanks for the help nsathees.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.