How to get the short code applied content inside a plugin using

add_filter('the_content', 'myfun_contentrender');

I have a situation like append some text to the content and also need to wrap all images inside a div.

I am doing something like this,

function myfun_contentrender($content){
    $content = do_shortcode($content);
libxml_use_internal_errors(true);
    $dom = new DOMDocument();
    $dom->loadHTML($content);
    $new_div = $dom->createElement('div');
    $new_div->setAttribute('class','wwm_socialshare_imagewrapper');
    $ImageList = $dom->getElementsByTagName('img');
    foreach($ImageList as $key => $Image)
    {
        if($Image->parentNode->nodeName === 'a')
        {
            $class_names = $Image->parentNode->getAttribute('class');
            $Image->parentNode->setAttribute('class',$class_names.' wwm_socialshare_imagewrapper ');            
            }else{
                $new_div_clone = $new_div->cloneNode();
                $Image->parentNode->replaceChild($new_div_clone,$Image);
                $new_div_clone->appendChild($Image);
            }
        }
        $content = $dom->saveHTML();
       // return the processed content
       return $content.$hidden_ul;
}

when I use $content = do_shortcode($content); inside my myfun_contentrender() It breaks the content like all white spaces comes like

$request_token               =   $_SESSION['request_token'];
$request_token_secret   =   $_SESSION['request_token_secret'];
$oauth_verifier                =   $_GET['oauth_verifier'];

So is there any option to get all short code applied content inside my myfun_contentrender() using add_filter()

Hope some expert can help me.

Read more here: do_shortcode inside my plugin breaks content


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , ,

Wordpress related questions and answers: