- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
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.
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
Any idea how to use include inside a shortcode without using the ob_start()... ?
- United Kingdom
- Community Superstar
- Attended a Community Meetup
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Sold between 5 000 and 10 000 dollars
- Has been a member for 2-3 years
- Microlancer Beta Tester
- Bought between 100 and 499 items
- Referred between 10 and 49 users
$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
- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Has been a member for 4-5 years
- Item was Featured
- Microlancer Beta Tester
- Author was Featured
- Bought between 50 and 99 items
- Referred between 50 and 99 users
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” ?
