Anyone who reads this blog knows that I love Elementor. But one challenge I’ve had is figuring out how to include dynamic content.
I talked a few months ago about how I was able to use shortcodes to insert practically any dynamic content. As great as that was, that didn’t solve another use case I had: Displaying an Elementor visual element only for my site’s Patreon members.
Fortunately, with the help of another great (and free) plugin, Ad Inserter, this turned out to be simple.
Elementor Templates: Include Them Anywhere!
In my mind, Elementor is one of the best ways to design WordPress Web sites. Rather than force you to struggle with defining your own custom theme, Elementor provides a drag-and-drop editor you can use to design pages that look sleek and modern. You can use Elementor to design individual pages, such as a splash page for a product – or you can use it to design and deploy a new theme that applies to your entire WordPress site.
One of Elementor’s powerful features is templates. A template is a canned design element that can be reused across multiple pages.
Typically, you include templates in pages or other templates using Elementor’s UI editor. However, Elementor also provides a way to insert any template anywhere in WordPress using a shortcode. Every template you save in Elementor has a shortcode assigned to it that you can find and copy in Templates -> Saved Templates in WordPress.
AdInserter + Elementor: Make Including Any Elementor Template Conditional
That’s all well and good. But what if you want to display one of these items conditionally? For example, let’s say you have a Patreon membership button. But you don’t want it to display for users who have already logged in.
Unfortunately, Elementor has few visibility controls. Elementor lets you show a template only to logged-in users. However, it won’t let you hide content for logged-in users, which is what we want.
This is where AdInserter comes in. AdInserter is a great little plugin for WordPress that lets you place content – typically, ad blocks – in various locations throughout your site. For example, you could use it to place ad blocks after the seventh paragraph of every blog post.
AdInserter has an almost ridiculous number of options. One of them allows you to show a block only to users who aren’t logged in. This is exactly what we want. Since AdInserter also supports WordPress shortcodes, we can tell it to include our Elementor template at the bottom of every post on our site:
Then, we click the Misc button (highlighted above) and, under Insertion, for the option Insert for, we select not logged in users.
And we’re done! The Patreon button will now be hidden for anyone who’s logged in.
Note that this works only if your logged in users are guaranteed to be members. If that’s not the case, you can use AdInserter’s taxonomy feature to restrict display by user role. The AdInserter site documents this in detail.
Hopefully, this tip helps you gain more power out of Elementor!