- This topic has 14 replies, 3 voices, and was last updated 5 years, 8 months ago by
RJ.
-
AuthorPosts
-
November 23, 2018 at 3:14 am #735682
RJ
Hi there – I have created an element hook for one of my banners. Is there a way to dynamically insert the page slug into the
&utm_term=page-slugparameter?TIA, Robin
November 23, 2018 at 9:07 am #736315Tom
Lead DeveloperLead DeveloperHi there,
You can try creating a shortcode:
add_shortcode( 'get_current_slug', function() { global $post; return $post->post_name; } );Then use
[get_current_slug]in your Element.November 23, 2018 at 9:40 am #736357RJ
Hi Tom – Thanks for replying. I must be doing something wrong as that didn’t appear to work.
I inserted the code you wrote into the Snippet plugin.
https://www.screencast.com/t/DkJYnoTRYQ
And inserted the shortcode into the Element, see
https://www.screencast.com/t/q9cj82qI9w
TIA
Robin
November 23, 2018 at 9:42 am #736362Tom
Lead DeveloperLead DeveloperIs “Execute Shortcodes” checked in the Hook?
November 23, 2018 at 9:50 am #736367RJ
You and your team are such rockstars Tom!
Cough (embarrassingly). Fiddle with fingers. Look the other way… err, no I hadn’t checked the ES box.
I have now, and it works a treat… thanks so much.
ATB, Robin
November 23, 2018 at 1:54 pm #736666Tom
Lead DeveloperLead DeveloperYou’re very welcome! 🙂
July 22, 2020 at 3:47 am #1371898RJ
I have just revisited this and am having a bit of trouble.
I have an Element at the bottom of every page with a hyperlinked button that takes people to: https://www.eatweeds.co.uk/foraging-in-summer/?source=xxx
I am trying to insert the page slug and have tried this:
https://www.eatweeds.co.uk/foraging-in-summer/?source=[get_current_slug]However, it doesn’t appear to work.
I have the following PHP snippet installed and have “Execute Shortcodes” checked in the Hook, as Tom suggested above:
add_shortcode( 'get_current_slug', function() { global $post; return $post->post_name; } );Any ideas? TIA
July 22, 2020 at 5:30 am #1372003David
StaffCustomer SupportHi there,
you could add the button HTML and full link inside your shortcode like so:
add_shortcode( 'get_current_slug', function() { global $post; $content = '<a class="button cta-link" href="https://www.eatweeds.co.uk/foraging-in-summer/?source=' . $post->post_name .'">Button Label</a>'; return $content; } );Then you just need to add your shortcode to the hook.
I added the GPbuttonclass and a customcta-linkclass for specific styling.July 22, 2020 at 6:08 am #1372045RJ
Hi David,
I have added what you suggested and it doesn’t appear to pass the slug through.
If you scroll to the bottom of this page:
https://www.eatweeds.co.uk/black-mustard-soupAnd look for the Foraging in Summer book, then click the button, you’ll see what I mean.
Any ideas what I might be doing wrong? TIA
July 22, 2020 at 6:35 am #1372075David
StaffCustomer SupportI am not seeing the new code.
Did you disable/delete the shortcode that Tom provided?
And make sure you only add[get_current_slug]to your hook. No HTML before it as my code already contains it.July 22, 2020 at 9:08 am #1372389RJ
I’m at a bit of a loss, David. I deleted Tom’s shortcode and replaced it with yours.
Here’s a 60-second screen recording of what I have done:
https://www.loom.com/share/74b7400a54be496a95e1cdce387a3a47TIA
July 22, 2020 at 2:26 pm #1372696Tom
Lead DeveloperLead DeveloperFrom the video it looks like “Execute PHP” is checked, but “Execute Shortcodes” is not. You’ll want to check that shortcodes option.
Then you can use my original function with the content you have in that Element as David’s will output the entire link.
July 22, 2020 at 2:56 pm #1372728RJ
That’s great. Thanks, Tom. I didn’t realise I needed two snippets, one for your code and the other for David’s.
Many thanks to you both.
July 23, 2020 at 12:35 am #1373015David
StaffCustomer SupportHi Robin – it should work now with just Toms snippet. As the issue before was the Execute Shortcodes was missing from the Hook element.
Either way glad to hear its working.
July 23, 2020 at 1:21 am #1373056RJ
Thanks, David.
-
AuthorPosts
- You must be logged in to reply to this topic.