Skip to content

Instantly share code, notes, and snippets.

@xnau
Created August 22, 2020 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/95d81c5e2479110f02ae32cbd577cade to your computer and use it in GitHub Desktop.
Save xnau/95d81c5e2479110f02ae32cbd577cade to your computer and use it in GitHub Desktop.
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
Copy link
Author

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