0

How would I go about adding the following shortcode properly to functions.php in WordPress? When I add it works but it isn't closed properly and gives me an error.

<?php echo do_shortcode( '[brb_collection id="297"]' ); ?>

I am getting the following error:

"Your PHP code changes were rolled back due to an error on line 55 of file wp-content/themes/betheme-child/functions.php. Please fix and try saving again.

syntax error, unexpected '<', expecting end of file"

Here is my functions.php

<?php

// // Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;

// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:

if ( !function_exists( 'chld_thm_cfg_locale_css' ) ):
    function chld_thm_cfg_locale_css( $uri ){
        if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) )
            $uri = get_template_directory_uri() . '/rtl.css';
        return $uri;
    }
endif;
add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' );

// END ENQUEUE PARENT ACTION

/* Tillad at uploade fonts */

function wp39550_disable_real_mime_check( $data, $file, $filename, $mimes ) {
	$wp_filetype = wp_check_filetype( $filename, $mimes );

	$ext = $wp_filetype['ext'];
	$type = $wp_filetype['type'];
	$proper_filename = $data['proper_filename'];

	return compact( 'ext', 'type', 'proper_filename' );
}
add_filter( 'wp_check_filetype_and_ext', 'wp39550_disable_real_mime_check', 10, 4 );

/* CF7 redirects */

add_action( 'wp_footer', 'redirect_cf7' );
 
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
   if ( '117' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
    location = 'https://example.com/thank-you/';
    } else if ( '118' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
        location = 'https://example.com/thank-you/';
    } else if ( '541' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
        location = 'https://example.com/da/tak/';
    } else if ( '542' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
        location = 'https://example.com/da/tak/';		
    }
}, false );
</script>
<?php
}

/* Google reivew widget */

<?php echo do_shortcode( '[brb_collection id="297"]' ); ?>

4
  • 1
    You'll probably need to show the code in wp-content/themes/betheme-child/functions.php here. May 24, 2020 at 22:13
  • 1
    Seems like your functions.php is ending with an unexpected character. Can you add the end / last view lines of your functions.php file?
    – rank
    May 24, 2020 at 22:15
  • Very unclear what you're trying to do here. Are you trying to use the shortcode "brb_collection" on a page, or are you trying to add a function that filters out shortcodes? May 24, 2020 at 22:24
  • I am trying to add the shortcode from a plugin as it'll display a Google Reviews widget on all pages of my site. have edited the post with all of my functions.php code to see where it goes wrong.
    – eMikkelsen
    May 25, 2020 at 21:59

1 Answer 1

0

You’re reopening php, while already in a php section

Just remove the php opening tag right before your last echo

Or close the previous php section before the comment /* Google reivew widget */

3
  • Hey Giovanni, thanks for your answer. I removed the php before echo and now it doesn't give me an error but then the review widget shows up weirdly in the header whereas before it showed up correctly but it gave me an error.
    – eMikkelsen
    May 26, 2020 at 14:35
  • Sounds like your shortcode is echoing content, while it should return content, have a look at the shortcode..
    – giovanni
    May 27, 2020 at 7:47
  • How would you do this?
    – eMikkelsen
    May 27, 2020 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.