Below, you’ll find a detailed guide on how to add the Pirate Forms Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Pirate Forms Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Pirate Forms Plugin and the shortcodes it provides:

"PirateForms is a Contact Form & SMTP Plugin for WordPress. It simplifies the process of creating and managing contact forms and seamlessly integrates with your email SMTP for efficient communication."
- [pirate_forms]
Pirate Forms [pirate_forms] Shortcode
The Pirate Forms shortcode is used to display a form in your WordPress site. It allows customization of form elements like name, email, subject, message, and more.
Shortcode: [pirate_forms]
Parameters
Here is a list of all possible pirate_forms shortcode parameters and attributes:
id
– Unique identifier for the contact form.from
– Indicates if the form is from a widget.ajax
– Enables or disables ajax form submission.
Examples and Usage
Basic example – Displaying a simple contact form using the Pirate Forms plugin
[pirate_forms]
Advanced examples
Displaying a specific form by referencing its ID. This will load the form with the specified ID.
[pirate_forms id="2"]
Enabling AJAX for the form. This will allow the form to submit without requiring a page reload.
[pirate_forms ajax="yes"]
Displaying a form from a widget. This allows you to display a form that was created in a widget.
[pirate_forms from="widget"]
Combining multiple parameters. This example shows a form with a specific ID, enabled AJAX, and is displayed from a widget.
[pirate_forms id="3" ajax="yes" from="widget"]
PHP Function Code
In case you have difficulties debugging what causing issues with [pirate_forms]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'pirate_forms', array( $plugin_public, 'display_form' ) );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | function display_form( $atts , $content = null ) { wp_enqueue_style( 'pirate_forms_front_styles' ); PirateForms_Util::session_start(); $atts = shortcode_atts( array ( 'from' => '' , 'id' => '' , 'ajax' => 'no' , ), $atts ); do_action( 'themeisle_log_event' , PIRATEFORMS_NAME, sprintf( 'displaying shortcode %s' , print_r( $atts , true ) ), 'debug' , __FILE__ , __LINE__ ); $form_id = isset( $atts [ 'id' ] ) && ! empty ( $atts [ 'id' ] ) ? intval ( $atts [ 'id' ] ) : 0; $from_widget = ! empty ( $atts [ 'from' ] ); $elements = array (); $pirate_form = new PirateForms_PhpFormBuilder(); $pirate_forms_options = PirateForms_Util::get_form_options( $form_id ); if ( ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_secretkey' ] ) && ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_sitekey' ] ) && ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) && ( 'yes' === $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) ) { wp_enqueue_script( 'google-recaptcha' ); } wp_enqueue_script( 'pirate_forms_scripts' ); $ajax = 'yes' === $atts [ 'ajax' ]; $elements [] = array ( 'type' => 'hidden' , 'id' => 'pirate_forms_ajax' , 'name' => 'pirate_forms_ajax' , 'value' => $ajax ? 1 : 0, ); $elements [] = array ( 'type' => 'text' , 'id' => 'form_honeypot' , 'name' => 'honeypot' , 'slug' => 'honeypot' , 'wrap' => array ( 'type' => 'div' , 'class' => 'form_field_wrap hidden' , 'style' => 'display: none' , ), ); $elements [] = array ( 'type' => 'hidden' , 'id' => 'pirate_forms_from_widget' , 'value' => $from_widget ? 1 : 0, ); $pirate_forms_options = PirateForms_Util::get_option(); if ( $form_id > 0 ) { $pirate_forms_options = apply_filters( 'pirateformpro_get_form_attributes' , $pirate_forms_options , $form_id ); if ( isset( $pirate_forms_options [ 'id' ] ) ) { // add the form id to the form so that it can be used when we are processing the form $elements [] = array ( 'type' => 'hidden' , 'id' => 'pirate_forms_form_id' , 'value' => $form_id , ); } } $nonce_append = $from_widget ? 'yes' : 'no' ; $error_key = wp_create_nonce( get_bloginfo( 'admin_email' ) . ( $from_widget ? 'yes' : 'no' ) ); $new_error_key = $nonce_append . '.' . $form_id ; $thank_you_message = '' ; if ( isset( $_GET [ 'done' ] ) && ! empty ( $_SESSION [ 'success' . $new_error_key ] ) ) { $thank_you_message = $_SESSION [ 'success' . $new_error_key ]; } $pirate_form ->set_element( 'thank_you_message' , $thank_you_message ); /** ******** FormBuilder */ if ( 'yes' === PirateForms_Util::get_option( 'pirateformsopt_nonce' ) ) { $elements [] = array ( 'type' => 'hidden' , 'id' => 'wordpress-nonce' , 'value' => wp_create_nonce( get_bloginfo( 'admin_email' ) . $nonce_append ), ); } if ( ! empty ( $pirate_forms_options ) ) { $field = $pirate_forms_options [ 'pirateformsopt_name_field' ]; $label = $pirate_forms_options [ 'pirateformsopt_label_name' ]; $subjectField = $pirate_forms_options [ 'pirateformsopt_subject_field' ]; /** ****** Name field */ if ( ! empty ( $field ) && ! empty ( $label ) ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( ( ! empty ( $subjectField ) ? 'col-xs-12 col-sm-6' : 'col-xs-12' ) . ' contact_name_wrap pirate_forms_three_inputs form_field_wrap' , ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-name' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'placeholder' => stripslashes ( sanitize_text_field( $label ) ), 'required' => $field === 'req' ? true : false, 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_name' ], 'type' => 'text' , 'id' => 'pirate-forms-contact-name' , 'value' => empty ( $thank_you_message ) && isset( $_REQUEST [ 'pirate-forms-contact-name' ] ) ? $_REQUEST [ 'pirate-forms-contact-name' ] : '' , 'wrap_class' => implode( ' ' , $wrap_classes ), ); } $field = $pirate_forms_options [ 'pirateformsopt_email_field' ]; $label = $pirate_forms_options [ 'pirateformsopt_label_email' ]; /** ****** Email field */ if ( ! empty ( $field ) && ! empty ( $label ) ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( ( ! empty ( $subjectField ) ? 'col-xs-12 col-sm-6' : 'col-xs-12' ) . ' contact_email_wrap pirate_forms_three_inputs form_field_wrap' , ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-email' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'placeholder' => stripslashes ( sanitize_text_field( $label ) ), 'required' => $field === 'req' ? true : false, 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_email' ], 'type' => 'email' , 'id' => 'pirate-forms-contact-email' , 'value' => empty ( $thank_you_message ) && isset( $_REQUEST [ 'pirate-forms-contact-email' ] ) ? $_REQUEST [ 'pirate-forms-contact-email' ] : '' , 'wrap_class' => implode( ' ' , $wrap_classes ), ); } $field = $pirate_forms_options [ 'pirateformsopt_subject_field' ]; $label = $pirate_forms_options [ 'pirateformsopt_label_subject' ]; /** ****** Subject field */ if ( ! empty ( $field ) && ! empty ( $label ) ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( 'col-xs-12 contact_subject_wrap pirate_forms_three_inputs form_field_wrap' , ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-subject' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'placeholder' => stripslashes ( sanitize_text_field( $label ) ), 'required' => $field === 'req' ? true : false, 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_subject' ], 'type' => 'text' , 'id' => 'pirate-forms-contact-subject' , 'value' => empty ( $thank_you_message ) && isset( $_REQUEST [ 'pirate-forms-contact-subject' ] ) ? $_REQUEST [ 'pirate-forms-contact-subject' ] : '' , 'wrap_class' => implode( ' ' , $wrap_classes ), ); } $field = $pirate_forms_options [ 'pirateformsopt_message_field' ]; $label = $pirate_forms_options [ 'pirateformsopt_label_message' ]; /** ****** Message field */ if ( ! empty ( $field ) && ! empty ( $label ) ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( 'col-xs-12 contact_message_wrap pirate_forms_three_inputs form_field_wrap' , ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-message' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'placeholder' => stripslashes ( sanitize_text_field( $label ) ), 'required' => $field === 'req' ? true : false, 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_no_content' ], 'type' => 'textarea' , 'id' => 'pirate-forms-contact-message' , 'value' => empty ( $thank_you_message ) && isset( $_REQUEST [ 'pirate-forms-contact-message' ] ) ? $_REQUEST [ 'pirate-forms-contact-message' ] : '' , 'wrap_class' => implode( ' ' , $wrap_classes ), ); } $field = $pirate_forms_options [ 'pirateformsopt_attachment_field' ]; /** ****** Attachment field */ if ( ! empty ( $field ) && 'no' !== $field ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( 'col-xs-12 form_field_wrap contact_attachment_wrap' ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-attachment' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'required' => $field === 'req' ? true : false, 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_no_attachment' ], 'type' => 'file' , 'title' => __( 'Upload file' , 'pirate-forms' ), 'id' => 'pirate-forms-attachment' , 'wrap_class' => implode( ' ' , $wrap_classes ), ); } if ( array_key_exists ( 'pirateformsopt_checkbox_field' , $pirate_forms_options ) ) { $field = $pirate_forms_options [ 'pirateformsopt_checkbox_field' ]; $label = $pirate_forms_options [ 'pirateformsopt_label_checkbox' ]; /** ****** checkbox field */ if ( ! empty ( $field ) && ! empty ( $label ) ) { $required = $field === 'req' ? true : false; $wrap_classes = array ( 'col-xs-12 form_field_wrap contact_checkbox_wrap ' ); // If this field was submitted with invalid data if ( isset( $_SESSION [ $error_key ][ 'contact-checkbox' ] ) ) { $wrap_classes [] = 'error' ; } $elements [] = array ( 'front_end' => true, 'required' => $required , 'required_msg' => $pirate_forms_options [ 'pirateformsopt_label_err_no_checkbox' ], 'type' => 'checkbox' , 'id' => 'pirate-forms-contact-checkbox' , 'wrap' => array ( 'type' => 'div' , 'class' => implode( ' ' , apply_filters( 'pirateform_wrap_classes_checkbox' , $wrap_classes ) ), ), 'value' => isset( $_REQUEST [ 'pirate-forms-contact-checkbox' ] ) ? $_REQUEST [ 'pirate-forms-contact-checkbox' ] : '' , 'options' => array ( 'yes' => stripslashes ( $label ), ), ); } } /** ******* ReCaptcha */ if ( ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_secretkey' ] ) && ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_sitekey' ] ) && ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) && 'yes' === $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) { $pirateformsopt_recaptcha_sitekey = $pirate_forms_options [ 'pirateformsopt_recaptcha_sitekey' ]; $pirateformsopt_recaptcha_secretkey = $pirate_forms_options [ 'pirateformsopt_recaptcha_secretkey' ]; $elements [] = array ( 'front_end' => true, 'id' => 'pirate-forms-captcha' , 'placeholder' => stripslashes ( sanitize_text_field( $label ) ), 'type' => 'captcha' , 'custom' => array ( 'data-sitekey' => $pirateformsopt_recaptcha_sitekey ), 'id' => 'pirate-forms-captcha' , 'wrap' => array ( 'type' => 'div' , 'class' => implode( ' ' , apply_filters( 'pirateform_wrap_classes_captcha' , array ( 'col-xs-12 ' . ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] !== 'yes' ? 'col-sm-6 ' : '' ) . 'form_field_wrap form_captcha_wrap' ) ) ), ), ); } if ( ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) && 'custom' === $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) { $elements [] = array ( 'front_end' => true, 'type' => 'spam' , 'id' => 'pirate-forms-maps-custom' , ); } /** ****** Submit button */ $pirateformsopt_label_submit_btn = '' ; if ( ! empty ( $pirate_forms_options [ 'pirateformsopt_label_submit_btn' ] ) ) { $pirateformsopt_label_submit_btn = $pirate_forms_options [ 'pirateformsopt_label_submit_btn' ]; } if ( empty ( $pirateformsopt_label_submit_btn ) ) { $pirateformsopt_label_submit_btn = __( 'Submit' , 'pirate-forms' ); } $elements [] = array ( 'front_end' => true, 'type' => 'button' , 'id' => 'pirate-forms-contact-submit' , 'name' => 'pirate-forms-contact-submit' , 'class' => 'pirate-forms-submit-button btn btn-primary ' . ( $ajax ? 'pirate-forms-submit-button-ajax' : '' ), 'wrap' => array ( 'type' => 'div' , 'class' => implode( ' ' , apply_filters( 'pirateform_wrap_classes_submit' , array ( 'col-xs-12 ' . ( ( ! empty ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] ) && ( $pirate_forms_options [ 'pirateformsopt_recaptcha_field' ] !== 'yes' ) ) ? 'col-sm-6 ' : '' ) . 'form_field_wrap contact_submit_wrap' ) ) ), ), 'value' => $pirateformsopt_label_submit_btn , ); } /* Referring site or page, if any */ if ( ! empty ( $_SERVER [ 'HTTP_REFERER' ] ) ) { $elements [] = array ( 'type' => 'hidden' , 'id' => 'pirate-forms-contact-referrer' , 'value' => $_SERVER [ 'HTTP_REFERER' ], ); } /* Referring page, if sent via URL query */ if ( ! empty ( $_REQUEST [ 'src' ] ) || ! empty ( $_REQUEST [ 'ref' ] ) ) { $elements [] = array ( 'type' => 'hidden' , 'id' => 'referring-page' , 'value' => ! empty ( $_REQUEST [ 'src' ] ) ? $_REQUEST [ 'src' ] : $_REQUEST [ 'ref' ], ); } /* Are there any submission errors? */ if ( ! empty ( $_SESSION [ 'error' . $new_error_key ] ) ) { $pirate_form ->set_element( 'errors' , $_SESSION [ 'error' . $new_error_key ] ); unset( $_SESSION [ 'error' . $new_error_key ] ); } $elements = apply_filters( 'pirate_forms_get_custom_elements' , $elements , $pirate_forms_options ); do_action( 'themeisle_log_event' , PIRATEFORMS_NAME, sprintf( 'displaying elements %s' , print_r( $elements , true ) ), 'debug' , __FILE__ , __LINE__ ); $output = $pirate_form ->build_form( apply_filters( 'pirate_forms_public_controls' , $elements , $pirate_forms_options , $from_widget ), $pirate_forms_options , $from_widget ); unset( $_SESSION [ 'success' . $new_error_key ] ); unset( $_SESSION [ 'error' . $new_error_key ] ); return $output ; } |
Code file location:
pirate-forms/pirate-forms/includes/class-pirateforms.php
Conclusion
Now that you’ve learned how to embed the Pirate Forms Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply