WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Encoding of apostrophes via the_title / get_the_title

[Resolved] Encoding of apostrophes via the_title / get_the_title

  • 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • use url_encode > a php class to handle URL’s

    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;
    }

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Encoding of apostrophes via the_title / get_the_title’ is closed to new replies.
Skip to toolbar