I create below shortcode in function.php in child theme.
function page_output_vc_shortcode($atts) {
$pagecontent = ”;
$arg = array(
‘page_id’=>$atts[‘page_id’]
);
$the_query = new WP_Query($arg);
while ($the_query->have_posts()) : $the_query->the_post();
$title = get_the_title();
$pagecontent = ‘<h2 class=”widgettitle”>’.$title.'</h2>’;
$pagecontent .= get_the_content();
endwhile;
return $pagecontent;
}
add_shortcode(‘my_vc_page_output’, ‘page_output_vc_shortcode’);
but it is not displaying page content. Same code is working fine on other theme with VC but it is not working with Newspaper theme VC.
Is there any settings i have to do with newspaper theme?
I want to display whole page content.
Hi,
I have tried your code and the shortcode
– https://www.screencast.com/t/wL9iScI6
It seems to produce an error while it displays some content
– https://www.screencast.com/t/vfHmLsWq
I don’t know exactly what you want to do, if you want to add a shortcode to Visual composer you can try it like this
– https://wpbakery.atlassian.net/wiki/spaces/VC/pages/524291/Shortcode+Mapper
– https://wpbakery.com/video-academy/add-shortcodes-wpbakery-page-builder-wordpress/
Thanks
page_id is param of the shortcode and you have to put pageid of one of the your page. Same shortcode is working fine on other theme. It is not working on Newspaper theme. It seems shortcode is not taking parameter page_id value in Newspaper theme.
What i am trying to do in my shortcode to display the whole page content in a box. I can use text element of VC for that but i don’t want other users to access VC if they want to make any changes.
Thanks
If you do not want users to be able to use Visual composer, note that this plugin has options to customize user roles
– https://www.screencast.com/t/PH5DxwP0FqaH
The page seems to display if you use the code like this
– https://www.screencast.com/t/MvNsEsFTiT
Maybe you can modify it further if needed, here it is
– https://pastebin.com/W2QG7zuS
Thanks
Hello Simon,
Thanks for the instance response. I tried the code which is working for you. But is not working for me.
https://www.screencast.com/t/WesXCltjl8
It seems shortcode is not calling the function at all.
https://www.screencast.com/t/dhGfokEbO
I changed the page_id to one of my page id. still nothing is displaying.
Below Report, it should display content of page as in report widget which i used texthtml.
https://www.screencast.com/t/eFoexKvA1
Thank you,
Pema
I think my function is not calling at all. I tried below function still it is not displaying anything. I put the below function in functions.php under child theme. I have only “add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’, 1001);” with theme_enqueue_styles function and below function in child theme’s functions.php.
// Shortcode to output a page content in Visual Composer
function page_output_vc_shortcode() {
$test_var = “This is just for testing”;
return $test_var;
}
add_shortcode(‘my_vc_page_output’, ‘page_output_vc_shortcode’);
Do i have to put above function in other file? My shortcode is listed in VC element.
Thank you
I simply placed the shortcode in a Visual composer page text element, and added the function in the child theme functions file
– https://www.screencast.com/t/owFJ6Kmi
– https://www.screencast.com/t/FPuc0vHVQN
The page ID used was of a different page which contained a block
– https://www.screencast.com/t/QzZESJGFz1
The result is like this – https://www.screencast.com/t/9bh39BGq0Gor
The block placed on the other page is displayed on the page with the shortcode. I did not do anything else additionally.
I couldn’t say why this is not working for you as well. You could continue testing, or maybe think of another way of doing this.
Thanks