- This topic has 32 replies, 4 voices, and was last updated 2 years, 5 months ago by David.
-
AuthorPosts
-
October 27, 2021 at 4:58 am #1977908DavidStaffCustomer Support
Ok… if the shortcode method works then lets try this. Be prepared for some brain scrambling.
1. First quick edit and change the status of the Hook Element that is outputting your shortcode to Draft. We may not need this… if this works.
2. Add this PHP Snippet to your site:
function db_hook_inside_shortcode($atts, $content = null) { ob_start(); do_action('db_custom_comparison'); return ob_get_clean(); } add_shortcode('hooky_shortcode', 'db_hook_inside_shortcode');
2. Now create your Block Element Page Hero for the Comparison table.
Start with a GB Container Block to create the section, which you cans style for color, padding etc.
Now add a shortcode block inside with this shortcode:[hooky_shortcode]
3. Now add this PHP Snippet:
add_action('db_custom_comparison', function(){ $comparison = get_post_meta( get_the_id(), 'comparison_shortcode', true ); if ( $comparison ) { echo do_shortcode( $comparison ); } });
So what it should do is output an empty hook inside your Block Element and the last function Hooks your custom field shortcode inside it.
Test to see if that works, and then we can look at the other stuff.
October 27, 2021 at 6:18 am #1978074StephenThanks,
I have gone through the steps and it looks like the comparison table is now showing above the content and in contained format.
So it looks like the code/hook/snippet works. All i now would like to add is the option to add a H2 title above the comparison table.
Again, thanks for your help.
October 27, 2021 at 6:32 am #1978111DavidStaffCustomer SupportThats great !
Ok so you can register a new custom field in your post. For examplehero_title
Now in the Block element add a GB Headline Block, and set its Dynamic Data to Post Meta and add your Custom Field name e.g
hero_title
in the field providedOctober 28, 2021 at 1:24 am #1979913StephenThat worked like a charm! Thanks!
One last question, sorry to keep going on.
I would like to add a button button with a hyperlink under the comparison table. How would I achieve this?
October 28, 2021 at 4:08 am #1980124DavidStaffCustomer SupportAwesome !
You can add a GB Buttons Block to your Block Element. The Label and the link both support dynamic data so you can use another custom field if you want.Or do you want it to Jump to a section on the page?
October 28, 2021 at 4:35 am #1980169StephenYes, the idea is to have it to jump to a section on the page.
Would that need a different way of adding a button?
October 28, 2021 at 5:34 am #1980258DavidStaffCustomer SupportJump links work like so:
1. The element you want to jump to is given a unique HTML Anchor/ID eg.
section
– name it what you like but it should be unique for that page. In the Block editor you add the ID by selecting the Block ( you want to jump to ) in Advanced > HTML Anchor.2. The Button that will jump to the element is give an URL that matches that ID prefixed with a
#
eg.#section
October 28, 2021 at 5:57 am #1980316StephenThanks!
And which PHP snippets do i need to add for the button title and button anchorlink?
October 28, 2021 at 7:59 am #1980757DavidStaffCustomer SupportNo need for PHP – You can use a GenerateBlocks Buttons block in your Block Element:
https://docs.generateblocks.com/article/buttons-overview/
Make sure you use the GB one and not the core one as this will provide you with full styling controls in the editor.
October 28, 2021 at 8:12 am #1980781StephenGot it,
But how would I set a link / text on button per page?
When i add the GB button I only seem to be able to add one link / text on button sitewide.
October 28, 2021 at 8:16 am #1980788DavidStaffCustomer SupportYou can set them using the same Dynamic Data options and pull in another Custom Field for the title and the link.
If its an on page link – i would assume the element you want to jump to would have the same ID ? You can use the same ID on every page.October 28, 2021 at 8:34 am #1980824StephenYes, that makes sense, using the same element for the page jump.
Where do i add the code for the dynamic data in the custom field? Do I set that in the elements/block section?
October 28, 2021 at 8:36 am #1980831DavidStaffCustomer SupportClick on the GB Button label where you would add the static text, and then in the Toolbar you will see the dynamic data option, select that, choose Post Meta, and add your Custom Field name in the field provided.
October 29, 2021 at 8:28 am #1982919StephenHi,
I tried that, but it does not seem to work for some reason.
I have added two screenshots in the private info with what I have done.
Thanks
October 29, 2021 at 8:45 am #1982938DavidStaffCustomer SupportAah.. there has to be something in the default URL field ( where it says ‘Paste URL or Type to Search’ ) – just add a
#
-
AuthorPosts
- You must be logged in to reply to this topic.