Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates how to let Participants Database know there is a shortcode on a page (see comments for full explanation)
// check for a specific post ID, then fire the action if it matches
add_action( 'wp', function () {
global $post;
if ( $post->ID == 9627 ) {
do_action( 'pdb-shortcode_present');
}
});
@xnau

This comment has been minimized.

Copy link
Owner Author

@xnau xnau commented Aug 22, 2020

Participants Database avoids loading it's content and assets on pages that don't have Participants Database content. Since the plugin is shortcode-based, it does this by inspecting the content of the current page and fires an action (pdb-shortcode_present) if a Participants Database shortcode is on the page.

With some types if shortcode placement (such as in a widget), the shortcode isn't actually in the page content, so the plugin doesn't know to load the assets. This code snippet provides a way to let Participants Database know it should load its assets on a particular page.

In the example, the page has an ID of 9727. Change that to be the post ID of the page you need the trigger the asset load on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment