本篇文章可不用使用外掛,而將將廣告碼放在文章中間,一種多寫文章賺稿費的概念 ^^
打開佈景主題下的 function.php,加入以下程式碼:
add_filter( 'the_content', 'wpse_ad_content' ); function wpse_ad_content( $content ) { if( !is_single() ) return $content; $paragraphAfter = 2; //填入數字,設定將廣告顯示在第幾行段落之後 $content = explode ( " ", $content ); $new_content = ''; for ( $i = 0; $i < count ( $content ); $i ++ ) { if ( $i == $paragraphAfter ) { $new_content .= ' <div style="margin:10px 50px;">'; $new_content .= '//將這裡替換貼上廣告代碼'; $new_content .= '</div> '; } $new_content .= $content[$i] . " "; } return $new_content; }
這樣就可以慢慢轉稿費囉,鼓勵大家多多寫文章囉 ^^
發表迴響