فلک زده
Registered User
- تاریخ عضویت
- 13 نوامبر 2014
- نوشتهها
- 587
- لایکها
- 2,917
- سن
- 43
ببین اینو داری؟
single.php
باید توی index.php , single.php واردش کنی اگه هم صفحه اصلی میخوای هم توی مطالب
این کد رو گذاشتم داخل index.php به هم ریخت قالب .
کد:
</span>
<pre><?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '[b]<div>Ads code goes here</div>[/b]';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}