Applying filters to the_content() to separate content if any `add_shortcode()` is found?

I don’t even know if this possible, with array_map or str_replace, but the idea is the follow:

This function gets the content and before is sent out, clean_custom_content, there is where i cant figure out how to procede.. so lets assume that we have all the content, this content it will be wrapped in a section but each time there is a short code[] this needs to be close and when the content of the short code has been outputted. them open a new section and continue with the content from that page.

Read More

make sense?
any ideas or help it will be great .. thanks

function get_custom_content( $more_link_text = null, $strip_teaser = false) {
    $content = get_the_content( $more_link_text, $strip_teaser );
    $content = apply_filters( 'the_content', $content );
    $content = str_replace( ']]>', ']]>', $content );
    $final_cotent = clean_custom_content($content);
    echo $final_cotent;
}

clean_custom_content()::

function clean_custom_content($content){
    if(do_clean_shorcode('someshorty')){
         $content = "<section>".$content.'</section>';
     return $content;
    }
    return null;
}

Related posts

1 comment

  1. This is very challenging for generic case since shortcodes can be nested, can be self-closing or enclosing and so on.

    If you need to do this on limited and fixed set of specific shortcodes that would be easier. I would unregister their shortcode handlers and register custom handlers that call original ones and add necessary markup around.

Comments are closed.