1

I'm having trouble removing paragraph tags from around shortcodes.

I've tried this solution without success. How to to stop html editor from addig <p> tags to shortcodes, images, etc and this one - the wordpress empty paragraph shortcode fix.

My shortcodes are created to have an open and close [div]---[end-div]. I'm not sure if that matters. See code example below.

add_shortcode('div', 'be_div_shortcode');
function be_div_shortcode($atts) {
    extract(shortcode_atts(array('class' => '', 'id' => '' ), $atts));
    $return = '<div';
    if (!empty($class)) $return .= ' class="'.$class.'"';
    if (!empty($id)) $return .= ' id="'.$id.'"';
    $return .= '>';
    return $return;
}
/* Close Div */
add_shortcode('end-div', 'be_end_div_shortcode');
function be_end_div_shortcode($atts) {
    return '</div>';
}

See screenshot of html: http://catalpha.com/images/code.png See screenshot of page editor: http://catalpha.com/images/builder.png

0

First, what you are trying to do is an abuse of the shorcode system. You should not use them to replace html elements.

That aside, the p comes from the content. You either need to use [div]....[/div] and than you will get the content as the second parameter to the shortcode function and you can format it anyway you want. This is how the first shortcode works in your example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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