1

Is it possible the executed a shortcode from a normal HTML?

For example: <a href=[shortcode]> press here</a> and when the user clicks the text, the shortcode is called?

I Basically I want to call elementors popup without using a freaking button, just want the users to be able to click in the text to get a pop-up with informations.

I know there are popup plugins that has that options, but "another" plug-in isn't necessary, beside no popup could be styled as good as elementor.

  • I you really want your pop-up plugin to just look like a link then are you able to style it like a link? Make it inline with the content, remove all the button 'appearance' and just keep it as a button. Or is it that you're encountering an issue where Elementor basically injects a ton of code to generate a button. I think this is only an issue because you're using something assumptive like Elementor (and other page builders). – Tony Djukic Apr 10 at 23:27
2

Yes and no

I created a shortcode named foo:

add_shortcode( 'foo', 'fooshort' );
function fooshort( $atts ) {
    return "https://google.com";
}

Then put this in a post:

test [foo]

The result:

test https://google.com

So if I take your question literally, yes, you can put shortcodes in anchor attributes. But the shortcode has no idea it's in an attribute. The shortcode could generate output that completely breaks the tag, and maybe even the page from that point onwards.

However

Shortcodes aren't magic tokens, they literally just get replaced with their output, and they have zero awareness of their context. That hasn't stopped page builders abusing them to imply they can do more. They're just substitutions, a way to embed something in post content that can't be put directly in the content, like an embed code, or an iframe, etc

Because of this, you can't apply any kind of logic to them as far as functionality goes. It's highly unlikely that your hyperlink will behave the same way a button does just by putting the shortcode in the href. However much plugin builders might suggest or imply it, there's no framework or system that adapts. Perhaps blocks in the block editor might be able to do that, but not shortcodes.

Shortcodes are dumb, they're just substitutions of shortcodes for content. Perhaps your plugin uses some logic that works off of the URL rather than something else, fingers crossed. Eitherway you're better off asking in the Elementor community for Elementor problems.

| improve this answer | |
  • Yeah, maybe best to ask the elementor community about this, was just interested if there was anyway to trigger the shortcode. Just because I put it in a href, didn't mean it was an address, I'm just after a clickable text that calls a shortcode, regardless what that shortcode do or displays. – JoBe Apr 10 at 18:53
  • I see, if my answer answers your question could you mark it as accepted? – Tom J Nowell Apr 10 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.