In this post I will cover how to use the do_shortcode function to imbed InfusionWP shortcodes in WordPress PHP files.
One of the great features of InfusionWP is the large number of shortcodes that are included out of the box that really let you do lot of creative things when setting up your membership or subscription site.
In addition to the over 246 built in shortcodes (and growing) there is even a short code module that allows you to create your own. Needless to say this opens up a lot of doors, and allows you to communicate with infusionsoft un a number of ways. And while I will save some of my favorite specific shortcodes and their uses for another post, right now I want to cover a great trick that will allow you to use shortcodes in the wordpress PHP files.
The do_shortcode function is the little piece of code that can really let you get creative with your subscription site.
WordPress Codex Link: Function Reference/do shortcode
Basically it will allow you to use any of the I4W shortcodes anywhere within the wordpress PHP files. So if you had a shortcode that you really wanted to get deep into your theme now it’s as simple as adding a single line of code.
Not much of an explanation needed – let’s take a look at two simple examples of the do_shortcode function in action.
InfusionWP PHP shortcodes in action
EXAMPLE 1: Adding login options that can only be viewed by logged in members
In this example I needed to add “membership” links to the nav area in a theme where the navigation was created by a PHP file. So when a member was not logged in it would say “member login” and after they had successfully logged in it would say: “upgrade”, “Account”, and “Logout”.
This was easily achieved using the following code:
As you can see I used a combination of the do_shotcodes function and the I4W ‘logged in’ shortcodes to create the menu links.
EXAMPLE 2: Creating a front page post loop that can only be seen by members in the index.php file
In this example I used the do_shortcodes and the not_logged_in shortcodes to create a different front page for logged in users and non-logged in users. So the non logged in users will simply see an image that asks them to log in using the sidebar and points them to the sales page if they are not a member.
Once the member logs in they will be able to view the video of the week which is simply the latest WP post.
RGRY Video Of The Week
[/i4w_not_logged_in]’); */ ?>
[/i4w_is_logged_in]’); */ ?>
Unfortunately I have not been able to get the shortcodes to work within PHP that is within the do_shortcodes function – that is why I had to point to an iframe in the above example. Not the ideal solution but until I can get the nested PHP to work it will have to do.
Important Notes: Some I4W shotcodes include variables that use ‘. It is important that you strip these out using strip slashes. More info here: http://php.net/manual/en/function.stripslashes.php
Also, it is important to add ‘echo’ the function – this part is not covered in the wordpress codex.
If you have any questions about how to use the shortcodes, infusionWP, infusionsoft, or wordpress please drop me a line, or leave a comment below.