render Visual Composer shortcodes onto page
Use the:
WPBMap::addAllMappedShortcodes();
then as usual do_shortcode($content);
In short, page builder due to performance doesn't register shortcodes unless it isn't required.
If your element is registered by vc_map
or vc_lean_map
then no need to use add_shortcode
function, you can do everything just by using WPBMap::addAllMappedShortcodes();
it is will call an shortcode class callback during the rendering process and then shortcode template.
Regarding Method 2.
You have to use do_shortcode()
in your shortcode function.
function someshortocode_callback( $atts = array(), $content = null ) { $output = '[vc_section full_width="stretch_row" css=".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}"][vc_row 0=""][vc_column offset="vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6"]column text[/vc_column][/vc_row][/vc_section]'; return do_shortcode( $output );}add_shortcode( 'someshortocode', 'someshortocode_callback' );
Working example on my test site: http://test.kagg.eu/46083958-2/
Page contains only [someshortocode]
. Code above is added to functions.php
.
In your code for Method 2 there is another error: line
echo add_shortcode('someshortocode', 'someshortocode_callback');
cannot work, as add_shortcode()
returns nothing. This code should be as follows:
<?php $post = get_post();if ( $post && preg_match( '/vc_row/', $post->post_content ) ) {// Visual composer works on current page/post wc_print_notice('VC ON', 'notice');} else { wc_print_notice('VC OFF', 'notice'); add_shortcode('someshortocode', 'someshortocode_callback'); echo do_shortcode('[someshortocode]');}; ?>