SAC Pro makes it easy to add a chat form to any post or page. Simply add the shortcode [sacpro form_id="123"]
and change the form_id
to whatever name you prefer. But what about adding a chat form to every post or page? Depending on the number of posts, it could take a lot of time to add shortcodes to all of them. But no worries. This quick tutorial explains how to do it with a bit of custom code.
Add chat to all posts
Here is the magic code snippet to automatically add chat form shortcode to every WordPress post.
function sacpro_add_shortcode_all_posts($content) {
if (is_single()) { // is a post
$content .= do_shortcode('[sacpro form_id="postID'. get_the_ID() .'"]');
}
return $content;
}
add_filter('the_content', 'sacpro_add_shortcode_all_posts');
You can add the code via theme functions or simple plugin. No changes need made, unless you want to customize with conditional logic, etc.
Add chat to all pages
Similar to the previous function, here we are adding the shortcode to all pages.
function sacpro_add_shortcode_all_pages($content) {
if (is_page()) { // is a page
$content .= do_shortcode('[sacpro form_id="postID'. get_the_ID() .'"]');
}
return $content;
}
add_filter('the_content', 'sacpro_add_shortcode_all_pages');
You can add the code via theme functions or simple plugin. No changes need made, unless you want to customize with conditional logic, etc.
Add chat to all posts and pages
Lastly, here is a function showing how to add the form shortcode to all posts AND pages.
function sacpro_add_shortcode_all_posts_pages($content) {
if (is_singular()) { // is a post or page
$content .= do_shortcode('[sacpro form_id="postID'. get_the_ID() .'"]');
}
return $content;
}
add_filter('the_content', 'sacpro_add_shortcode_all_posts_pages');
You can add the code via theme functions or simple plugin. No changes need made, unless you want to customize with conditional logic, etc.