php 广告文本小部件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 广告文本小部件相关的知识,希望对你有一定的参考价值。
// Registers `ad-content` widget area.
genesis_register_widget_area(
array(
'id' => 'ad-content',
'name' => __( 'Ad Content', 'text-domain' ),
'description' => __( 'This is the ad content section.', 'text-domain' ),
)
);
add_filter( 'the_content', 'custom_insert_widget_area' );
/**
* Filters the content to insert widget area after specified paragraph of single post content.
*
* @param string $content Existing post content.
* @return string Modified post content.
*/
function custom_insert_widget_area( $content ) {
ob_start();
genesis_widget_area( 'ad-content', array(
'before' => '<div class="ad-content widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
$widget_area_html = ob_get_clean();
if ( is_singular( 'post' ) ) {
$content = custom_insert_after_paragraph( $widget_area_html, 3, $content ); // change 3 to the paragraph after which you would like to insert the widget area.
}
return $content;
}
// Callback function that inserts the passed in HTML after the specified paragraph and returns the modified content.
function custom_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 );
}
以上是关于php 广告文本小部件的主要内容,如果未能解决你的问题,请参考以下文章
php 文本小部件中的短代码执行
php 从Genesis中删除省略号,在特色页面小部件中阅读更多文本
带类的Wordpress文本小部件
小部件测试以断言文本小部件样式
Dart/flutter 小部件测试,无论是按键还是文本都找不到文本小部件
未找到材质小部件 文本字段小部件需要材质小部件祖先