2210 posts
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+13 more
mpc says

Hi, I have a contact form shortcode which looks like this:

function contact_form_shortcode($params = array()) {
    extract(shortcode_atts(array(
        'fmail' => '#',
        'thanks' => 'Thank You - we will respond shortly.'

    ), $params));
    ob_start();
    include(get_theme_root() . '/' . get_template() . "/functions/contact_form.php");

    return ob_get_clean();
}

add_shortcode('contact_form', 'contact_form_shortcode');

For all of my shortcodes I am using a clean up method which looks like this:

function parse_shortcode_content( $content ) {

   /* Parse nested shortcodes and add formatting. */
    $content = trim( do_shortcode( shortcode_unautop( $content ) ) );

    /* Remove '' from the start of the string. */
    if ( substr( $content, 0, 4 ) == '' )
        $content = substr( $content, 4 );

    /* Remove '' from the end of the string. */
    if ( substr( $content, -3, 3 ) == '' )
        $content = substr( $content, 0, -3 );

    /* Remove any instances of ''. */
    $content = str_replace( array( '<p></p>' ), '', $content );
    $content = str_replace( array( '<p>  </p>' ), '', $content );

    return $content;
}

// move wpautop filter to AFTER shortcode is processed

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );

While with all of the shortcodes it works great, with the contact form I get an ‘unexpected token <’ I am not sure how should I run the parse_shortcodes_content function while I am using ob_start().

The simplest solution would be not too use the echo buffer (ob_start) but I am not sure how to use the include statement without printing out the shortcode always at the top of the page.

2210 posts
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+13 more
mpc says

Any idea how to use include inside a shortcode without using the ob_start()... ?

973 posts
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
aaranmcguire says
if you turn everything in the contact_form.php to a return, not echo then you could do
$code = include($path . 'contact_form.php');
$code = str_replace('<p></p>', '', $code);

I think anyway, not used this method ever but seen it done. if not, skype me: aaran.mcguire

343 posts Codestar
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $250,000+ on Envato Market
  • Sells items exclusively on Envato Market
  • Made it to the Authors' Hall of Fame
+7 more
Codestar says
ob_start();
include(get_theme_root() . '/' . get_template() . "/functions/contact_form.php");
return ob_get_clean();

can be used directly include. but if so you can’t use fmail, thanks params. just try it for error message. you can understand where is problem ob_start or not :)

return include(get_theme_root() . '/' . get_template() . "/functions/contact_form.php");

by the way, why you using an include there ? write your codes directly ? and add some code of contact_form.php and write all error line. just this “unexpected token” ?

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by