- This topic has 3 replies, 2 voices, and was last updated 1 year, 4 months ago by
Elvin.
-
AuthorPosts
-
January 26, 2021 at 10:42 pm #1635107
detanatar
is it possible to insert one hook into the content of the second hook?
January 26, 2021 at 11:41 pm #1635134Elvin
StaffCustomer SupportHi there,
I’m not sure I fully understand what you mean.
Can you explain a bit more? Perhaps be more specific in what you’re trying to do? Let us know. 🙂
A wise man once said:
"Have you cleared your cache?"January 27, 2021 at 11:04 am #1636030detanatar
there is a block “A” created by the hook,
this block is shown on pages 1, 2, 3, 4 …
inside block “A” block “B” is shown
Block “B” is created by hooks, and it is different for each page.
That is, there are hooks “B1”, “B2”, “B3”, “B4” ..before, for each page I created a summary block “AB1”, “AB2”, “AB3”, “AB4” …
Block “B” has little code, and I was planning to set up impressions in my pages for every “B” block, and insert links to blocks “B” in block “A”
January 27, 2021 at 7:11 pm #1636333Elvin
StaffCustomer SupportConsider this:
You can actually make a portable hook you can place anywhere.
Here’s an example creating a portable hook through a shortcode.
add_shortcode('portable_hook', function($atts){ ob_start(); $atts = shortcode_atts( array( 'hook_name' => 'no foo' ), $atts, 'portable_hook' ); do_action($atts['hook_name']); return ob_get_clean(); });
What this particular shortcode does is, it adds a hook anywhere you place this shortcode.
to use this, write shortcode in this manner
[portable_hook hook_name="my_custom_hook"]
wheremy_custom_hook
is the hook name.Try placing it anywhere in your site where shortcodes work.
Now to test it, you can use add_action() using
my_custom_hook
.Say for example, you to hook something inside this hook, you can do it the same way you add_action to other hooks.
Example:
add_action('my_custom_hook', function(){ echo 'added in portable hook shortcode'; });
We can also place this portable inside a hook.
Say for example, you want to place a hook named
special_hook
on another hook namedgenerate_after_header
.You can do it by using this:
add_action('generate_after_header',function(){ do_shortcode('[portable_hook hook_name="special_hook"]'); });
This shortcode was suggested so you can place your custom hooks within the content area.
But if you don’t want to bother with that and simply place a hook area within any existing hooks within the theme, then you can completely skip creating a shortcode and simply do something like this:
Example: placing
another_hook
hook within GeneratePress’generate_before_content
hookadd_action('generate_after_header',function(){ do_action('another_hook'); });
A wise man once said:
"Have you cleared your cache?" -
AuthorPosts
- You must be logged in to reply to this topic.