Shortcode difficulties


I’m reasonably familiar with Sage 9, but this problem has popped up and I cannot seem to get the shortcode to work unless I hardcode the actual shortcode text into the template, not ideal.

OK so I have added a setting page and numerous options, the option in question is for a shortcode for Contact Form 7, this is saved via the settings API and so far we’re all good.

when I want to display the shortcode I’ve been grabbing the option from the API with this:

function sign_up_form(){
	$sc = get_v('sign_up'); 
		return $sc;

this returns the shortcode and also works fine, ‘get_v’ grabs the option and in this case the result of that is: [contact-form-7 id=“188” title=“Sign Up”], so far so good.

Now I need to use that shortcode in a template file, so in my views/partials folder I’ve got a quick-contact.blade.php file with the following code:

@php $form = App\sign_up_form() @endphp
@php echo do_shortcode($form) @endphp

which outputs:
[contact-form-7 404 “Not Found”]

Now I know the shortcode is correct, when I run “@php echo do_shortcode(’[contact-form-7 id=“188” title=“Sign Up”]’) @endphp” instead of the two lines above the contact form appears.

I’m sure I’m making a basic mistake somewhere here but I can’t see it and it’s driving me mad! I’ve had a decent search around here for a solution without any joy… Any pointers much appreciated! TIA

What about

{!! do_shortcode(App\sign_up_form()) !!}


Can you post the actual code for get_v()?

1 Like

Hi thanks,

Yeah don’t think get_v is the problem, basically a helper to allow me to grab one of my theme options, but here’s the code:

function get_v($v){
	$opts = get_option('custom_theme_opts');
	if( isset( $opts[ $v ] ) ) {
		return esc_attr( $opts[ $v ] );
	} else {


[contact-form-7 404 "Not Found"]

Aha it was get_v()…
well done @alwaysblank!!

esc_attr() <- without this bit it’s working!

Sorry & thanks!!

1 Like

Glad you figured it out!

Yeah, esc_attr() is really just to keep element attributes from breaking the HTML of an element. Since a shortcode is just a string for WordPress to parse, your code doesn’t need to be sanitized in that way.