• Issue is that when you pull in page content using the [content] shortcode when the target page was built using visual composer, you have the following issues:
    1) page-level CSS does not come in (VC lets you add CSS to just that page)
    2) some alterations to columns and rows (e.g. background image) get stored as styles in a custom field which also need to be pulled in dynamically
    3) there are usually extra <p> and <br> tags, and sometimes extra whitespace which cause unwanted spacing.

    I can address #3 by simply doing something like [content format=false texturize=false id=230, but pulling in the page-level CSS and the element level CSS is more difficult. I have written a shortcode to do it for me. Here’s that code:

    add_shortcode( 'vc-all-custom-css', 'vc_all_custom_css' );
      function vc_all_custom_css ( $atts ) {
        // element level css (took this from the VC codebase because there's no function to do it
        $id = $atts['id'];
      	if ( $id ) {
          // generated by vc dialogs
          $shortcodes_custom_css = get_post_meta( $id, '_wpb_shortcodes_custom_css', true );
                if ( ! empty( $shortcodes_custom_css ) ) {
                    echo '<style type="text/css" data-type="vc_shortcodes-custom-css-'.$id.'">';
                    echo $shortcodes_custom_css;
                    echo '</style>';
                }
            }
        Vc_Base::addPageCustomCss( $id ); // page-level custom css
      }

    But this means that I need to use 2 shortcodes and pass the id of the post while in a loop to my new shortcode. It’s messy.

    I’d ideally like to extend custom content shortcode, adding a parameter like vc=true which would take care of all of this. e.g. [content id=230 vc=true]

    Is there a way I can extend the content shortcode to add my custom param and do the extra css formatting, as well as turn off formatting and texturize in one shot? I’d like to make this into a CCS extension plugin, or maybe add it to the CCS settings panel since I think VC has really taken off as a layout editor for WP.

    https://ww.wp.xz.cn/plugins/custom-content-shortcode/

The topic ‘Visual Composer compatibility – new param for [content]’ is closed to new replies.