Filter: mbp_autopost_post_args [Deprecated]

Deprecated - Use mbp_create_post or mbp_update_post instead.

The mbp_autopost_post_args filter allows you to alter the post arguments sent to Google My Business when the plugin creates an automatic post. It has 2 parameters, $args containing the post data and $location containing the GMB location ID.
<code>function do_something_with_the_post_args($args, $location){	
	//Alter the post arguments
	return $args;
}
add_filter('mbp_autopost_post_args', 'do_something_with_the_post_args', 10, 2);

Out of the box, Post to Google My Business will only auto-post "What's New" posts. But using this filter you can make it automatically create product, event and offer posts. This is very useful if you have a plugin that manages such content and you want to automatically publish it to Google My Business.

Samples

Strip Visual Composer, Divi and other shortcodes

Visual editors such as Divi, Visual Composer and others often clutter the post content with shortcodes. The following snippet will strip out the shortcodes.
function autopost_strip_shortcodes($args, $location){
	$args['summary'] = preg_replace("~(?:\[/?)[^\]]+/?\]~s", '', $args['summary']);
	return $args;
}
add_filter('mbp_autopost_post_args', 'autopost_strip_shortcodes', 10, 2);

Remove call to action button

<code>function autopost_remove_button($args, $location){	
	unset($args['callToAction']);	
	return $args;
}
add_filter('mbp_autopost_post_args', 'autopost_remove_button', 10, 2);

Alter call to action URL

<code>function autopost_change_button_url($args, $location){	
	$args['callToAction']['url'] = 'https://example.com';
	return $args;
}
add_filter('mbp_autopost_post_args', 'autopost_change_button_url', 10, 2);

Use Yoast OpenGraph image as GMB post image

function autopost_use_yoast_og_image($args, $location){
	$args['media']['sourceUrl'] = esc_url($_POST['yoast_wpseo_opengraph-image']);
	return $args;
}
add_filter('mbp_autopost_post_args', 'autopost_use_yoast_og_image', 10, 2);

Only publish posts with specific tag

Only publishes the WordPress post to GMB when the gmbpost tag is present
function only_post_from_specific_tag($args, $location){
global $post;
if(!has_tag('gmbpost', $post)){ return false; }
return $args;
}
add_filter('mbp_autopost_post_args', 'only_post_from_specific_tag', 10, 2);

Only publish posts within a specific category

Only publishes the WordPress post to GMB when it is in the gmbpost category
function only_post_within_specific_category($args, $location){
global $post;
if(!in_category('gmbpost', $post)){ return false; }
return $args;
}
add_filter('mbp_autopost_post_args', 'only_post_within_specific_category', 10, 2);
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us