Sitesao Support
  • Home
  • Themes
  • Plugins
  • Support

Support Forums

Home/Forums/Plugin & Extension/Easy View Shortcode in WPBakery Page Builder/VC shortcodes pasted into a Text widget?

VC shortcodes pasted into a Text widget?

This topic is: not resolved
  • January 28, 2016 at 3:29 pm #9909

    BuchmannDesign
    Participant

    Hi. A couple days ago I posted in the comments, and I was invited to continue this in this forum.

    My question was if it’s possible to copy/paste VC shortcodes into a regular “text widget” (for a sidebar, footer, etc.) This can work, except shortcode padding, margins, borders, and backgrounds get ignored. In the comments I was told the following code put into functions.php will make it work:

     

    add_filter('widget_text', 'dhvc_view_shortcode_parse_custom_css',0);
    function dhvc_view_shortcode_parse_custom_css2($content){
        $css = '';
        if ( preg_match( '/\s*(\.[^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $content ) ) {
            WPBMap::addAllMappedShortcodes();
            preg_match_all( '/' . get_shortcode_regex() . '/', $content, $shortcodes );
            foreach ( $shortcodes[2] as $index => $tag ) {
                $shortcode = WPBMap::getShortCode( $tag );
                $attr_array = shortcode_parse_atts( trim( $shortcodes[3][ $index ] ) );
                if ( isset( $shortcode['params'] ) && ! empty( $shortcode['params'] ) ) {
                    foreach ( $shortcode['params'] as $param ) {
                        if ( 'css_editor' === $param['type'] && isset( $attr_array[ $param['param_name'] ] ) ) {
                            $css .= $attr_array[ $param['param_name'] ];
                        }
                    }
                }
            }
    
            foreach ( $shortcodes[5] as $shortcode_content ) {
                $css .= dhvc_view_shortcode_parse_custom_css2( $shortcode_content);
            }
        }
        return $css;
    }
    function dhvc_view_shortcode_parse_custom_css($content){
        if(!class_exists('WPBMap'))
            return $content;
        $css = '';
        if ( ! preg_match( '/\s*(\.[^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $content ) ) {
            return $content;
        }
        WPBMap::addAllMappedShortcodes();
        preg_match_all( '/' . get_shortcode_regex() . '/', $content, $shortcodes );
        foreach ( $shortcodes[2] as $index => $tag ) {
            $shortcode = WPBMap::getShortCode( $tag );
            $attr_array = shortcode_parse_atts( trim( $shortcodes[3][ $index ] ) );
            if ( isset( $shortcode['params'] ) && ! empty( $shortcode['params'] ) ) {
                foreach ( $shortcode['params'] as $param ) {
                    if ( 'css_editor' === $param['type'] && isset( $attr_array[ $param['param_name'] ] ) ) {
                        $css .= $attr_array[ $param['param_name'] ];
                    }
                }
            }
        }
        foreach ( $shortcodes[5] as $shortcode_content ) {
            $css .= dhvc_view_shortcode_parse_custom_css2( $shortcode_content );
        }
    
        return (!empty($css) ? '<style type="text/css">'.$css.'</style>' : '' ).$content;
    }

     

     

    With this code, if one of my shortcodes contains any margins, borders, padding, or background, then the entire contents in the text widget will not display at all.

    I was told in the comments that it should work, and if not then post in the forum. Thanks so much for any help with this!


    Sorry, this forum is for verified users only. Please Login or Register to continue

Log In
Register Lost Password

Forums

  • Theme & Template
  • Plugin & Extension

Our Themes

Our Plugins

Tags

acf Button cart conditional logic css demo email Error footer form gallery Header Image Images layout login luxury mailchimp Menu mobile Modal newsletter Newsri not working page plugin product product page products recaptcha shortcode Sidebar Single Product Page spam Submit Submit button template translate Translation update Visual Composer woocommerce Woo Detail Product Page Builder woow WPML
© Copyright Sitesao.com - Support Policy