2017-03-03 3 views
0

私のショートコード出力は常に自分のカスタムテンプレートの一番上に表示されます。ショートコード出力は常にカスタムテンプレートの先頭に表示されます

カスタムテンプレート

$tag= 'the_content'; 
remove_all_filters($tag); 
$postid = get_the_ID(); 
$post = get_post($postid); 
$content = do_shortcode($post->post_content); 

ob_start(); 
echo $content; 
$result = ob_get_contents(); 
ob_end_clean(); 
return $result; 

カスタムショート

function signupform_shortcode($atts) { 
    extract(shortcode_atts(array(
     'socialmkt' => 'aweber' 
    ), $atts)); 

    if($socialmkt == 'aweber'){ 
     if($display == 'popup') { 
     return include_once('modal-aweber.php'); 
     } 

    } 
} 
add_shortcode('signupform', 'signupform_shortcode'); 

それはHTMLの着陸の途中の場所ですショート。 私は他の投稿で読んだがまだ動作していないob_start()を追加しようとしています。

+0

'modal-aweber.php'これはhtmlの特定の場所に印刷する必要がある現在のhtmlです。 –

答えて

2

あなたのショートコードコールバックはコンテンツを返すのではなく、コンテンツを出力するため、ページの上部に表示されています。

出力バッファリング(ob_start()/ob_get_contents())を使用すると、問題を解決する有効な方法ですが、コードを移動する必要があります。

出力バッファリングは、出力ではなく戻り値が必要なショートコードコールバック内で実行する必要があります。

function signupform_shortcode($atts) { 
    extract(shortcode_atts(array(
     'socialmkt' => 'aweber' 
    ), $atts)); 

    // Begin output buffering here. Any output below will be stored in a buffer. 
    ob_start(); 

    if ($socialmkt == 'aweber') { 
     if ($display == 'popup') { 

      // Return, as previously used, doesn't help in this context. 
      include_once('modal-aweber.php'); 
     } 

    } 

    // Return (and delete unlike ob_get_contents()) the content of the buffer. 
    return ob_get_clean(); 
} 
add_shortcode('signupform', 'signupform_shortcode'); 
+0

答えをありがとう!私は何も言わず何もしなかった。カスタムテンプレートから(ob_start()/ ob_get_contents())を削除し、カスタムショートコードに追加しました。その解決策の横に、私は両方のファイルで(ob_start()/ ob_get_contents())を試しました。 –

+0

作品パーフェクト!それはキャッシュに関する問題でした。 –

関連する問題