如何在wordpress中创建短代码?

时间:2017-04-25 03:09:53

标签: php wordpress

当我运行以下内容时,我得到:

  

解析错误:语法错误,意外'如果' (T_IF)in   / home3 /

function list_pages_function( $atts, $content ) {
    return
    if(ICL_LANGUAGE_CODE=='en'){
        echo "Define topic and title";
      }
      if(ICL_LANGUAGE_CODE=='es'){
        echo "Definir el tema y título";
      }
      if(ICL_LANGUAGE_CODE=='it'){
        echo "Definisci il topic ed il titolo";
      }
      if(ICL_LANGUAGE_CODE=='fr'){
        echo "Définir le sujet et le titre";
      }
    }
  add_shortcode( 'output_pages', 'list_pages_function' );

如果我删除return就可以了,但是当我放置<li id="a"><strong>1.</strong>[output_pages]</li>时,输出不会在<li>内,但它会在内容突破的顶部布局

1 个答案:

答案 0 :(得分:0)

这就是我如何解决它:

function list_pages_function( $atts, $content ) {
if(ICL_LANGUAGE_CODE=='en'){
    $eng1 = "Define topic and title";
 return   $eng1;
  }
  if(ICL_LANGUAGE_CODE=='es'){
    $es1 = "Definir el tema y título";
   return $es1;
  }
  if(ICL_LANGUAGE_CODE=='it'){
    $it1 = "Definisci il topic ed il titolo";
  return  $it1;
  }
  if(ICL_LANGUAGE_CODE=='fr'){
    $fr1 = "Définir le sujet et le titre";
  return $fr1;
  }
}
add_shortcode( 'output_pages', 'list_pages_function' );
相关问题