Support » Plugin: Spectra - WordPress Gutenberg Blocks » Generate styles on a different page

  • Resolved Steve Jones

    (@stevejonesdev)


    Is it possible to generate the UA styles on a different page. I’m pulling the_content of a post into a taxonomy archive page but none of the UA styles get generated.

    Is there a way to pass in a post_id to the print_stylesheet() function and return the styles?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support BSF – Sweta Kumari

    (@swetakumari)

    Hello @stevejonesdev ,

    Unfortunately, as of now, there is no direct option. But I would love to take this as a suggestion.

    I will surely convey your feedback to our concerned developers. We are always keen to listen to our customers and to receive their feedback. This is the best way to improve our products and services and maintain our client’s satisfaction. 🙂

    I’ll put forward your thought about this to our team and if feasible we will try to improve the scenario in our future updates.

    If you have any further queries, please don’t hesitate to contact us.

    Regards,
    Sweta

    I had a similar situation recently where I wanted to be able to stick a reusable block outside of the editor (after blog post content on all posts in this case). I did some digging and got it working with the code below. I ran it on the wp hook, and $post is the post object for my block (but passing any post should work.

    $uagb_helper = UAGB_Helper::get_instance();
    $uagb_helper->get_generated_stylesheet( $post );

    get_generated_stylesheet() checks for UAGB blocks in the post and adds any needed styles/scripts to the list of assets the plugin will enqueue.

    Obviously this is not official, but I hope it helps!

    • This reply was modified 1 year, 3 months ago by scottjd. Reason: clarity
    Thread Starter Steve Jones

    (@stevejonesdev)

    @scottjd,

    I was able to get it working with the code you provided. I did have to enqueue the UAGB styles as well (blocks.style.css).

    Thanks for your help!

    Thread Starter Steve Jones

    (@stevejonesdev)

    This solution no longer works as the functions used are now deprecated. You can now use the Assets API to achieve this.

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

    https://ultimategutenberg.com/docs/assets-api-third-party-plugins/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Generate styles on a different page’ is closed to new replies.