Site logo

Archived topic

Element in multiple hooks

10 replies · Started by David on April 30, 2021

Viewing posts 1–11 of 11

Hello,

Is there a way to put an element in more than one hook location using GP premium

Hi there,

Unfortunately not. You would need to create multiple elements.

No problems, that is a shame though.

Hi there,

out of interest - what would be the use case ? Be good to know how you're intending to use them.

It was just for example placing a button after the primary nav on desktop and in mobile below the nav

Aah ok ... depending on the layout you could probably use some CSS with the right hook to position. But it sounds like it would be simpler to use 2 x elements.

Interesting though - we'll have a chat internally to see if that could be something for the future.

Thank you for the consideration, is there much of a resources overhead for for having multiple elements. I'm just trying to get my head around the new template system to see if I can us into style an events manager plugin layout, only problem is how I find out the custom field names used.

is there much of a resources overhead for for having multiple elements.

No not really. Theres hardly any difference between them and you adding the content directly to the post editor.
There is the Display Rules which is setting an IF condition for the hooks content to be displayed, but this is super efficient.

The plugin developer should be able to provide you with a list of the their post meta ( custom fields ).

Or if you want to get your hands dirty - this article provides a function that will display all the meta fields being used on the post your viewing:

https://wpbeaches.com/show-all-post-meta-keys-and-values-for-a-post-in-wordpress/

I have the same request. Use case is this:
I have created a block element CTA (promoting an eBook for example) and I would like to show it in two hook locations. Once after the featured image, and again at the end of the content. This seems like it should be possible. I don't like the idea of creating multiple copies of the same element.

Hi there,

there is no functionality in GP Elements that would allow that.

The only work around it is to create your own custom hook inside the two theme hooks, and then hook your block element inside that. Heres an example function:

add_action('generate_before_header', 'db_custom_hook');
add_action('generate_before_footer', 'db_custom_hook');

function db_custom_hook(){
	do_action('custom_hook');
}

Then in the Block element you can select Hook > Custom Hook --> named: custom_hook to add a block element to two places.
You just need to update the hook names in the add_action functions to suit your needs.

This feature would be great. I currently have an element I need to display in 2 different areas - and also use as a content template on a CPT archive page.

This archived topic is closed to new replies.