Archived topic
Issue with adding Ultimate Addons for Gutenberg
3 replies · Started by Jens on November 24, 2021
Hi there!
I have an issue with adding blocks of Ultimate Addons for Gutenberg to element blocks. When added to an element the scripts (CSS, JS) are not loaded compared to just adding such a block to a page or a post.
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_by_post_id' );
function enqueue_scripts_by_post_id() {
// Create Instance. Pass the Post ID.
$post_assets_instance = new UAGB_Post_Assets( $post_id );
// Enqueue the Assets.
$post_assets_instance->enqueue_scripts();
}
What I don't know:
- How can I actually pass a specific post id?
- How can I adjust the code so that it applies to a specific post type or all pages?
Many thanks in advance!
PS: after having used this support forum already and having received great help. Is there a way to donate some money to the team?
Hi there,
you can simply use the get_the_ID(); function.
https://developer.wordpress.org/reference/functions/get_the_id/
And you can use the get_post_type() function to test what post type your on.
For example:
add_action( 'wp_enqueue_scripts', 'enqueue_scripts_by_post_id' );
function enqueue_scripts_by_post_id() {
if ( 'your_post_type' == get_post_type() ) {
$post_id = get_the_id();
// Create Instance. Pass the Post ID.
$post_assets_instance = new UAGB_Post_Assets( $post_id );
// Enqueue the Assets.
$post_assets_instance->enqueue_scripts();
}
}
Thanks!
You're welcome