Shortcode won't work in Visual Editor Area

I added the following code into extras.php to use for this shortcode: [jbox], but it’s not rendering at all.

/*  jBox Shortcode */
function jbox_shortcode( $atts, $content = null ) {
	return str_replace("\r\n", '', '<div class="jbox clearfix">' . do_shortcode($content) . '</div>');
}
add_shortcode( 'jbox', 'jbox_shortcode' );

Can you please help me find what’s going wrong?

1 Like

I have read the writeup and have successfuly implemented __NAMESPACE__ with add_filter but not with add_shortcode. How can I modify this snippet so that it works properly with namespaces?

/**
 * Add Picturefill Shortcode
 */
function responsive_insert_image($atts) {
  extract( shortcode_atts( array(
    'id'    => 1,
    'caption' => ''
  ), $atts ) );
  $sources = add_picture_sources($id);
  return '<figure class="responsive_img">
  <picture>
  <!--[if IE 9]><video style="display: none;"><![endif]-->' .
  $sources .
  '<!--[if IE 9]></video><![endif]-->
  <img srcset="' . wp_get_attachment_image_src($id, 'smallest')[0] . '" alt ="' . get_img_alt($id) . '">
  </picture><figcaption class="et_pb_text et_pb_text_align_center">' . $caption . '</figcaption></figure>';
}
add_shortcode( 'resp_image', 'responsive_insert_image' );

It’s the same, you still need to pass the namespace with responsive_insert_image, assuming you’re in a namespaced file.

add_shortcode( 'resp_image', __NAMESPACE__ . '\\responsive_insert_image' );
1 Like

Thanks @kalenjohnson! It worked.