Site logo

Archived topic

Create one function to generate multiple pieces of information

6 replies · Started by Rekindle on September 14, 2021

Viewing posts 1–7 of 7

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!

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. :D

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.

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. :D

Thanks Elvin. Will look into it.

No problem. Let us know if you need further help. We'll see what we can do. :D

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.

This archived topic is closed to new replies.