[Resolved] Create one function to generate multiple pieces of information

Home Forums Support [Resolved] Create one function to generate multiple pieces of information

Home Forums Support Create one function to generate multiple pieces of information

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1930874
    Rekindle

    Hi,

    I’ve moved most of my site to GenerateBlocks, and I love it! There are a couple of pages that are still holding out. One of these is a page that has 3 pieces of information that need to be generated by a plugin (a heading, a subheading, etc). See screenshot below.

    I’d like to move this to GenerateBlocks too. I could have a shortcode inside each of those 3 blocks.

    But the issue is that this will create 3 different function calls inside the custom plugin. Each of these function calls will have some common code at the start – they will each need to retrieve all custom posts of a type, loop through them, find one, etc. (screenshot below) This seems unnecessary and may slow down that page.

    Is there a way around this? This is our most important page on the site so I’m eager to move it to GenerateBlocks too.

    Thanks!

    #1930882
    Elvin
    Staff
    Customer Support

    Hi there,

    I’m not exactly sure how the plugin calls the values but if the plugin has shortcodes for that then you can place the shortcode that generates the values inside a shortcode block and place that shortcode block inside a container block.

    Or check if the plugin actually adds blocks to Gutenberg editor and use that instead. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1930885
    Rekindle

    Hi Elvin,

    I understand that. I currently have one shortcode that generates the entire content of the page. I would like to replace that with 3 shortcodes. Each of those will have some common code at the start. I’d like to avoid that common code being run 3 times. Is there a way to avoid that?

    This is a custom plugin so I can change it.

    Thanks.

    #1930890
    Elvin
    Staff
    Customer Support

    Third-party or custom plugins are out of the theme’s scope.

    But to help you out:

    It really depends on how the common function is declared and how the overall code is structured.

    If you can share the code’s repository, I can do a quick check and recommend things.

    While waiting: If the common function is something that generates a template for different contents then it makes sense that it runs everytime its called. If this is the case then you should just let it do its thing. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1930892
    Rekindle

    Thanks Elvin. Will look into it.

    #1930895
    Elvin
    Staff
    Customer Support

    No problem. Let us know if you need further help. We’ll see what we can do. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1930979
    mkjj

    Functions in the child theme are usually processed very, very fast. I don’t think this will have an impact on the performance. However, why not just trying it? You will immediately see, if there’s a significant difference. Keep us posted, please. I’m very interested in the results.

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