Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
This is exactly what I was looking for and worked perfectly. Thanks. Can you elaborate on how echoing raw stuff is a poor idea for security? –  Jartron Oct 19 '11 at 0:24
    
@Jartron it is general security concept that any output should be properly cleaned in a way appropriate to output context. See Data Validation > Output Sanitation in Codex. –  Rarst Oct 19 '11 at 9:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.