I have a custom vc_map in my function and here is my Code:
vc_map( array(
'name' => __( 'myname Article Content', 'myname' ),
'base' => 'myname-article-content', //my shortcode name
'class' => '',
'icon' => 'icon-wpb-vc_carousel',
'category' => __( 'Content', 'myname' ),
'description' => __( 'Content for Article', 'myname' ),
'params' => array(
array(
'type' => 'textfield',
'heading' => __( 'Image Caption', 'myname' ),
'param_name' => 'caption',
'description' => __( 'Enter text which will be used as Image Caption.', 'myname' )
),
array(
'type' => 'textfield',
'heading' => __( 'Image credits', 'myname' ),
'param_name' => 'credits',
'description' => __( 'Enter text which will be used as Image credits. Leave blank if no title is needed.', 'myname' )
),
array(
'type' => 'textarea_html',
'holder' => 'div',
'heading' => __( 'Content', 'myname' ),
'param_name' => 'body_text',
'description' => __( 'Enter the Body of the news', 'myname' )
)
)
) );
and here is my short code:
add_shortcode('myname-article-content','myname_article_content');
function myname_article_content($atts){
$atts = shortcode_atts( array(
'caption' =>'',
'credits' => '',
'body_text'=> ''
), $atts );
extract($atts);
$cat = get_the_category()
?>
<span class="category"><?php echo $cat[0]->name;?></span>
<h2 class="popular-business"><?php the_title();?></h2>
<div class="post-author"><strong>Published by:</strong> <?php the_author(); ?> <strong>Published Date</strong> <?php the_date(); ?></div>
<?php
if ( has_post_thumbnail() ):
$feat_image_url = wp_get_attachment_url( get_post_thumbnail_id() );
else:
$feat_image_url = MYTHEME_THEME_DIR_URI.'/assets/images/blank-img.png';
endif;?>
<div class="post-img" >
<img src="<?php echo $feat_image_url ?>" alt="Image">
</div>
<p><?php echo $caption;?></p>
<?php if($credits != '') {?>
<p><strong>PHOTO BY</strong> <?php echo $credits;?></p>
<?php } ?>
<hr class="divider-full">
<p><?php echo $body_text;?></p>
<?php add_action('myname_text', $body_text); ?>
<div class="gap gap-30"></div>
<p><strong>Share</strong></p>
<div class="gap gap-30"></div>
<?php
}
in this codes.. the only thing that is not working properly is the textarea_html in my visual composer.
if the content has no image added the vc_map is operational in the editor and in the frontend.
But when I add an image, after saving the content in the editor, the contents in the textarea_html will be shown in the holder and that’s where it should be, BUT when i click edit again it can’t fetch the content of the textarea_html but the other contents like textfields are shown.
and another thing, when i click update post.. if there is no image added the post is working fine in the frontend, but when i add image or any media the content cannot be shown.
any ideas? Thanks..
I found help on this [Envato support page].(https://forums.envato.com/t/render-visual-composer-shortcodes-onto-page/126965)
For others searching, this is how you echo
textarea_html
content from Visual Composer. Read this iftextarea_html
is not echoing or yourtextarea_htm
l is not working.If you check method 2, you will see that
$content
is passed as an argument along with$atts
.In your case, you need to change the
param_name
tocontent
:…and pass in the
$content
variable:function myname_article_content($atts, $content)
Hope this helps others!
Here’s the code that works for me,
param_name
should be content.$content
along with$atts
in the function that you use for returning HTML.shortcode_atts
.Here’s an example: