Site logo

Archived topic

Easily adding a piece of code

6 replies · Started by Pawel on July 12, 2021

Viewing posts 1–7 of 7

Hello team,

I'm not sure if this is possible but I would like to create a small piece of content (like a call of action) and quickly add it to the chosen posts via a shortcode.

The location would be limited to certain posts only, and the location within the post would also differ from post to post.

I know there are plugins like that but I was wondering if I could use Elements for it without installing yet another plugin.

Please let me know.

Cheers!

Hi there,

are you using the Block Editor ? If so you can save your CTA Content as a Reusable Block, then add that to where you need it. And in the future if you want to update it across the site you can simply edit the Reusable block...

Hi David,

thank you. To be honest I prefer writing in Classic editor to keep everything clean. Is there any other way to achieve this functionality?

You would need to create your own shortcode. Heres a simple PHP Snippet example:

add_shortcode('my-cta-shortcode',function() {
    $html = '<div class="cta-container">Something in my CTA</div>';
    $styles = '<style>/* your CSS Styles here */</style>';
    $html .= $styles;
    return $html;
});

which creates this shortcode: [my-cta-shortcode] but you can rename that to something more suitable.

Thank you, David, I appreciate your help. Where does it go, to functions.php?

Glad to hear that.
And thanks for sharing the plugin option.

This archived topic is closed to new replies.