Archived topic
Can I use Elements as shortcut?
7 replies · Started by Neronet on October 3, 2022
Can I use Elements as shortcut?
I mean Can I use Element manual in specific post or page? by paste the code in post?
Hi there,
What kind of element are you talking about?
If it's a block element, why not save it as a reusable block, so you can add it to post/page via block editor?
If it's a hook element, what will the content be?
Let me know!
It is code of JavaScript and i need to add it in 200 posts, then if I need to change this code i want to change it in one place, not manual in every post of 200 posts.
Hi Neronet,
A Hook Element would be perfect for this.
Just add the Script through the hook, and set the display rule location to your preference.
Reference: https://docs.generatepress.com/article/hooks-element-overview/
A Hook Element you dont give me shortcut to put it where I want in post; right?
I need shortcut to use it wherever I want in post. t.ex I have age calculator code (html,java,css) and i want to use it in specific posts not all the category.
After 1 year i want to update this code so I have to edite about 75 articles manaul, it will take time, so i need edite the code in one place and it will change in every have this code.
Where exactly do you want it to appear in posts? Would the location in each posts be identical?
not specific location t.ex here
https://ibb.co/vQ64nzz
For one, you can add a Portable Hook:
function portable_func($atts, $content = null) {
ob_start();
do_action('portable_hook');
return ob_get_clean();
}
add_shortcode('portable-shortcode', 'portable_func');
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Now, you can add [portable-shortcode] Shortcode in your posts, and then use hook portable_hook in your Hook Element.
This should hook your script in your preferred location.