Custom Shortcodes

Shortcodes in WordPress thing is very convenient: we can call the functions we need anywhere in the page or record. They are very often used by various plug-ins, for example, Contact Form 7 generates a shortcode for the generated form, inserting which on the page, we call in this place the required form. But what if the form is self-written and is in a separate php file? Let’s create your shortcode in the function.php file:

First, create a function that will connect the third-party contact_form.php file from the folder with the theme:

function form_include($attr) {
   $includes_path = TEMPLATEPATH . '/';
   require_once ($includes_path .$attr[name].".php");	

Then create a new short form [form] using the add_shortcode() function:

add_shortcode('form', 'form_include');

Our shortcode is ready and we can call the file anywhere on the page, for example so

[form name="contact_form"]

Inside the name attribute, specify the name of the file to attach.

Требуется подобная доработка? Напишите нам.