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.

Quick question here. I have a function that echoes out the post-type's content (if none available, the excerpt). It looks like this:

function era_excerpt($post, $length = 11, $ext = ' ..') {
    if(is_int($post)) { $post = get_post($post); } elseif(!is_object($post)) { return false; }
    if(has_excerpt($post->ID)) { $the_excerpt = $post->post_excerpt; } else { $the_excerpt = $post->post_content; }
    $the_excerpt = strip_shortcodes(strip_tags(stripslashes($the_excerpt), '<a><em><strong>'));
    $the_excerpt = preg_split('/\b/', $the_excerpt, $length * 2+1);
    $excerpt_waste = array_pop($the_excerpt);
    $the_excerpt = implode($the_excerpt);
    $the_excerpt .= $ext;
    $post = $post->ID;

    return apply_filters('the_content', $the_excerpt);
}

I realized this function had a major issue: users starting a post-type with a special HTML tag, such as <em>, <a> and/or <strong>, broke the whole layout. Assuming this was caused by the "allowed tags" parameter of *strip_shortcodes*, I changed the function to:

function era_excerpt_new($post, $length = 11, $ext = ' ..') {
    if(is_int($post)) { $post = get_post($post); } elseif(!is_object($post)) { return false; }
    if(has_excerpt($post->ID)) { $the_excerpt = $post->post_excerpt; } else { $the_excerpt = $post->post_content; }
    $the_excerpt = strip_shortcodes(stripslashes($the_excerpt));
    $the_excerpt = preg_split('/\b/', $the_excerpt, $length * 2+1);
    $excerpt_waste = array_pop($the_excerpt);
    $the_excerpt = implode($the_excerpt);
    $the_excerpt .= $ext;
    $post = $post->ID;

    return apply_filters('the_content', $the_excerpt);
}

Sadly, this has not prevented users from breaking the layout whenever they start*º* a post-type's content with (and probably other tags I am not aware of).

º I say start because, so far, adding tags in-between text has not broken anything.

My question is, how can I allow my users to use any tag they want when publishing a post-type, and echo the contents of it without breaking my site.

Thank you!

share|improve this question
    
how does the layout break - are the starting tags unclosed in the html? have you tried to apply some code to close any open tags - such as stackoverflow.com/questions/3810230/… ? –  Michael Jan 18 '12 at 16:47
    
Hey Michael, thanks for your reply - I already managed to fix it though. It wasn't a regular "break"; it actually replaced and wrapped all following tags of the website/theme with the tag used in the post-type. Thus my confusion. –  cr0z3r Jan 18 '12 at 19:14
add comment

1 Answer

up vote 2 down vote accepted

Try removing the stripslashes() function.

share|improve this answer
    
Oh wow, awesome! –  cr0z3r Jan 18 '12 at 16:35
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.