PMC Sponsored Posts
This plugin is for use with any child theme using the pmc-core-v2 theme. If you are not using the pmc-core-v2 theme, you'll to need to apply the pmc_core_global_curation_modules filter where a theme creates its global curation.
Setup instructions
PMC Sponsored Posts plugin needs to be made aware of all the sponsored post placements (required), their template path (required), and sponsored text* (optional) via the pmc_sponsored_posts_config filter. There are legacy setups that only use pmc_sponsored_posts_template, but anything new should use this setup. Also note the legacy setup does not support post rotation (see below).
*Note it is important to include %s in sponsored text as this is where the sponsor name goes.
Example
function my_config( $config = [] ) {
return array_merge(
$config,
[
'hp_river' => [
'template' => __DIR__ . '/templates/hp-river-sponsored-post.php',
'sponsored_text' => 'In partnership with %s',
],
'widget' => [
'template' => __DIR__ . '/templates/widget.php',
'sponsored_text' => 'In partnership with %s',
],
]
);
}
add_filter( 'pmc_sponsored_posts_template', 'my_post_template', 10, 2 );Usage
For placing a sponsored post, you should do_action on pmc_sponsored_posts_placement. This will add a sponsored post to that placement if one is currently active. Add the optional** $context variable that can be used to determine a specific template. You can also pass $sponsored_text, which sets the text around the sponsor. Default sponsored text is Sponsored By %s or what is set in pmc_sponsored_posts_config within that context. Note it's important to include %s in the text, as this is where the sponsor name goes. In most cases you will want to handle $sponsored_text in pmc_sponsored_posts_config filter, so you will not have to add it directly to the do_action.
**$context is not optional for post rotation (see below). In almost every case you will want to add the $context variable to this do_action.
Example
// Within template.
do_action( 'pmc_sponsored_posts_placement', 'hp_river', 'In partnership with %s' );
// In most cases using `pmc_sponsored_posts_config` setup, you will only need this as sponsored text should be handled in the config.
do_action( 'pmc_sponsored_posts_placement', 'hp_river' );
Optional settings
Template override
You can use pmc_sponsored_posts_template to override any template that is either not set or set in pmc_sponsored_posts_config. You will see legacy setups using this method of setup along with the $context argument. This legacy setup does not support post rotation (see below).
Example
function my_post_template( $template, $context ) {
return __DIR__ . '/templates/sponsored-post.php';
}
add_filter( 'pmc_sponsored_posts_template', 'my_post_template', 10, 2 );Post option override
You can specify a post option with the pmc_sponsored_posts_post_option filter to assign sponsored posts to. By default, the post option is sponsored-content See example below for overriding.
Example
function my_post_option( $post_option ) {
return [
'name' => 'New Sponsored Option',
'slug' => 'new-sponsored-option',
];
}
add_filter( 'pmc_sponsored_posts_post_option', 'my_post_option' );Post rotation
Post rotation is enabled when more than one sponsored post is active on a given date. You also need to use pmc_sponsored_posts_config filter to set sponsored posts placements for post rotation to work.
If you would like to disable post rotation completely, you can use the following filter.
add_filter( 'pmc_sponsored_posts_enable_rotator', '__return_false' );Widget sponsored text override
You should use pmc_sponsored_posts_config to set this, but you can also override the sponsored text for the widget (which does its do_action within the plugin) with the pmc_sponsored_posts_widget_text filter.
Example
function my_widget_text( $text ) {
return '<em>In partnership with</em> <strong>%s</strong>';
}
add_filter( 'pmc_sponsored_posts_widget_text', 'my_widget_text' );