0

I'm trying to write a function that will use a string (which will be a url once working) sent from a shortcode, but all it's sending back is the default value in the function.

My shortcode is

[youtube-thumb-url videoUrl="test"]

My function is below:

add_shortcode('youtube-thumb-url', 'get_youtube_thumb_url_func');
function get_youtube_thumb_url_func($atts)
{
extract(shortcode_atts(array(
    'videoUrl' => 'urlhere',
    ), $atts));

return $videoUrl;
}

Instead of returning "test", it's returning "urlhere". If 'urlhere' is left empty, it returns nothing.

1 Answer 1

0

It appears like you can not use upper case like that in a shortcode. Instead of videoUrl, use video-url:

function get_youtube_thumb_url_func( $atts ) {
    $atts = shortcode_atts(
        array(
            'video-url' => 'urlHere',
        ), $atts, 'youtube-thumb-url' );

    return $atts['video-url'];
}
add_shortcode( 'youtube-thumb-url', 'get_youtube_thumb_url_func' );

And your shortcode:

[youtube-thumb-url video-url="test"]

This is the final function that I tested before posting.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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