How To Add A WordPress Plugin Code To PHP File

I thought that I would take a second to write out a quick blog post on how to insert plugin code to a php file so that WordPress will execute the plugin code instead of displaying the literal text. This is my project…

I’m building a custom wordpress website for FrankPerea.com, a Midland Texas mortgage company, and ran into an issue where I needed to insert the plugin code, [salesforce form=”2″] into the template.php file. The plugin is a form for the plugin: WordPress-to-Lead for Salesforce CRM.

Here is how it looks when I add plugin code to a php file. See how its only plain text. No bueno!

Add WordPress Plugin to Php file

 

I’m sure that the issue is still the same for any plugin when you try to insert the plugin code inside any .php file instead of the standard WordPress page of post.

So without further ado, here is the code for adding WordPress plugin code to a php file:

<pre><?php echo do_shortcode('[salesforce form="X"]');?></pre>

Obviously, this is my code for the WordPress-to-Lead for Salesforce plugin, but you will need to insert your plugin code instead inside the ‘ and ‘.

Here is how the website looked when I used the WordPress do_shortcode function:

insert wordpress plugin to php file

Obviously it doesn’t look visually appealing, but it’s just proof that the do_shortcode WordPress function works!

If you have questions on your project, give me a holler and comment below!

WordPress do_shortcode function Details:

The do_shortcode function searches content for shortcodes and will filter the shortcode through their hooks. Here is an example:

<?php echo do_shortcode( $content ) ?>

The do_shortcode ($content) requires a string for it’s parameter and returns the content replaced by the output from the shortcode’s handler.

Meaning, that the do_shortcode will search your wordpress site to see if there is a plugin that matches your plugin code and when it does, it will run that code.

What are your thoughts? Write a comment below!

Your email address will not be published. Required fields are marked *