Hướng dẫn tạo shortcode Polylang

Đầu tiên bạn chèn đoạn mã sau vào functions.php của theme

function polylang_shortcode($atts, $content = null)
{
  if (empty($content))
    return '';
  extract( shortcode_atts( array('lang' => ''), $atts ) );
  if (empty($lang))
    return "### You must specify 'lang' using shortcode: polylang";
  return ($lang == pll_current_language()) ? $content : '';
}
add_shortcode('polylang', 'polylang_shortcode');

Sử dụng shortcode như sau:

[polylang lang="en"]WordPress Vietnam Team[/polylang][polylang lang="vi"]Cộng đồng WordPress Việt Nam[/polylang]

Chúc các bạn thành công