Outputting post title without encoding

I’m setting up a way to feed the title of a WP post as the title argument for a reddit button. It works fine unless there is an encoded character in the string:

apostrophe’s break things.

…Which results in reddit double encoding the ampersand:

Read More
apostrophe’s break things.

I’ve tried the functions the_title_attribute(), the_title(), html_entity_decode(), and htmlspecialchars_decode() all to no avail – certain encodings remain.

Anyone know a way around this? Like a way to get the raw unencoded title from the database?

Thanks!

Related posts

Leave a Reply

1 comment

  1. Try this:

    $title = get_post_field('post_title', $post_id, 'raw');
    

    However I’d get to the bottom of what encoding reddit code would prefer. Echoing raw stuff is poor idea for security.