Yes it’s possible,
$value = get_field( "your_url_field" );
[iframe src=”$value”]
Oh great! Where do I put
$value = get_field( "your_url_field" );
?
I’ve been playing around with this and failing miserably.
The only thing that happens is that I get the literal text, not the output of the code.
Just a tip, based on my own miserable coding failures. 🙂
if ( $value = get_field( "your_url_field" ) ) {
do_something_with ( $value );
} else {
echo "No URL field entered."
}
wrapping it in an if covers you when the field has not been filled.
So I added
<script>$resSida = get_field( "resultatsida" );
</script>
To the header of the page, then call it using
[iframe src=$resSida]
And I get a “page can not be found” error. (I also tried with [iframe src="$resSida"]
)
Linking a std youtube page works.
So, question is what am I doing wrong? The field is a ACF-field if that matters, and I’ve double checked that the fieldname is correct.
the <script>
tag is to enable JavaScript. The code you show is PHP. You need to write a PHP function and include it either in your (child) theme’s functions.php or in a custom plugin.
I’d create a function *something like* this… note that I am not providing production ready code!
<?php
function my_acf_iframe_shortcode( $atts, $content ) {
if ( $ressida = get_field( 'resultatside' ) ) {
$str = '<iframe src="' . $ressida . '" other iframe parameters here ></iframe>';
return $str;
} else {
return '';
}
}
add_shortcode( 'iframe', 'my_acf_iframe_shortcode' );
Hmm, I tried
<?php
function my_acf_iframe_shortcode( $atts, $content ) {
if ( $ressida = get_field( 'resultatsida' ) ) {
$str = '<iframe src="$ressida . width="100%" height="500"></iframe>';
return $str;
} else {
return '';
}
}
add_shortcode( 'iframe', 'my_acf_iframe_shortcode' );
echo "DEBUG: ressida = " . $ressida;
But $ressida is empty. Despite it having a value in the ACF field.
Am I missing something?
I scaled the entire thing down to just picking up the field value – it comes up empty every time…