[英]Wordpress - How to add a button into a Wordpress' post and make it work?
[英]How to add button by default in WordPress Post
我有一个简单的WordPress网站和一个按钮的代码片段。 我想要的是,每当我创建一个新的WordPress帖子时,我都希望默认情况下该特定的按钮代码出现在我的新POST中。 我试图将其硬编码到我的WordPress帖子文件中,但无法正常工作。 这是我到目前为止尝试过的
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
return $content;
}
它有效,但仅适用于文本数据,不适用于HTML。 任何指导方针将不胜感激。
谢谢。
您需要使用the_content过滤器,方法如下:
function add_button_to_all_posts($content) {
return $content."If you like this post, then please consider retweeting it or sharing it on Facebook. <a href='yourlink'>button here</a>";
}
add_filter( 'the_content', 'add_button_to_all_posts' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.