• Resolved Creatrix

    (@chrisl_57)


    I have an advanced custom field that i would like to output within a shortcode that i’ve created. My code looks like this:

    // Adding shortcode for Title
    	$cta_title = get_field('cta_title');
    	function cta_func( $atts, $content = null ) {
    		return '<div class="black-box">
                                <h2 class="white">' . $cta_title . '</h2>
                            </div>
    		';
    	}
    	add_shortcode( 'cta', 'cta_func' );

    Have I declared the variable in the wrong place?

Viewing 1 replies (of 1 total)
  • Thread Starter Creatrix

    (@chrisl_57)

    If any one happens to stumble across this in the future:

    // Adding shortcode for Title
    	function cta_func( $atts, $content = null ) {
    		return '<div class="black-box">
                                <h2 class="white">' . $cta_title = get_field('cta_title'); . '</h2>
                            </div>
    		';
    	}
    	add_shortcode( 'cta', 'cta_func' );
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying a variable within a custom shortcode’ is closed to new replies.