[Resolved] Issue with adding Ultimate Addons for Gutenberg

Home Forums Support [Resolved] Issue with adding Ultimate Addons for Gutenberg

Home Forums Support Issue with adding Ultimate Addons for Gutenberg

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2019575
    Jens

    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?

    #2020164
    David
    Staff
    Customer Support

    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();
    
        }
        
    }
    #2021962
    Jens

    Thanks!

    #2021984
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.