在wordpress所有文章第二段落中插入广告

将下面这段代码添加到网站根目录下functions.php文件中,添加到文件的最后即可。如果你添加了没有生效,先清空缓存试试,再看看你使用的主题模板是否有单独的functions.php自定义文件调用。

function insert_after_first_paragraph($content) {
if (!is_single()) return $content;
$content_parts = explode('

', $content); if (count($content_parts) > 1) { $inserted_content = '
这里改成你的广告代码或超链接
'; $content_parts .= '

' . $inserted_content; $content = implode('

', $content_parts); } return $content; } add_filter('the_content', 'insert_after_first_paragraph'); function add_custom_styles() { echo '';

} add_action(‘wp_head’, ‘add_custom_styles’);```

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键