Roots Discourse

Sage 10 Shortcode Issue


I’m working on a website redesign which heavily use shortcodes.

I’m trying to “import” this shortcode used in their previous theme into my new one (based on sage).

        function mot_player($atts){
	global $post;
	if($post->post_type == 'videos' && is_single()){
	  $autoplay = 1;
	$allow_autoplay = $autoplay ? 'autoplay' : '';
	if (strpos( $atts["url"], 'dailymotion' )){
	  $url = explode('/', $atts["url"]);
	  $url = "".end($url);
	  $url = add_query_arg('autoplay',$autoplay,$url );
	  $short_code =   '<iframe class="iframe-container" width="100%" controls allow="'.$allow_autoplay.'" src="'.$url.'"></iframe>';
	  $short_code =  '<video class="video-container" width="100%" controls  '.$allow_autoplay.' > <source src="'.$atts["url"].'" type="video/mp4"> </video>';
	return $short_code;


Yet, when I use this snippet into sage10, Wordpress has an error. It tells " Attempting to parse a shortcode without a valid callback’

I must do something the wrong way. But what? Would you have an idea please?

I don’t know where you put this code, but my guess is that you’ve put it in one of Sage’s PHP files, most of which are namespaced, and then attempted to call the callback without a namespace. I’d recommend reading our blog post on namespacing and autoloading, but the immediate fix is probably to add the namespace to your callback, i.e.

add_shortcode( 'mot_video', __NAMESPACE__ . '\\mot_player' );

Yes. That’s it. Stupid mistake. Thank you!