我正在使用这个简单的功能向我的wordpress站点帖子添加文本!
add_filter( \'afip_new_post_content\', \'myprefix_change_afip_post_content\', 10, 2 );
/* Grabs the image source for the newly created image and inserts it
* into the new post content along with a one line paragraph. */
function myprefix_change_afip_post_content( $post_content, $attachment_id ) {
$my_uploaded_image = wp_get_attachment_image_src( $attachment_id );
$post_content = \'<p>This is my new uploaded image....</p>\';
return $post_content;
我正在尝试添加标题、作者和日期
$post_content = \'<p>This is my new uploaded image....</p>\';
如何在上述文本中插入wordpress帖子标题、帖子作者和日期
喜欢
$post_content = ‘This post – $post_title() ; is uploaded by the_author() on the_time() on category the_category()
SO网友:David Gard
因为你的钩子只经过$post_content
和$attachment_id
, 您首先需要获得相关职位,然后才能输出所需的数据。
请尝试此操作,如果不符合您的要求,请进行评论。
function myprefix_change_afip_post_content( $post_content, $attachment_id ) {
global $post
$post = get_post( $attachment_id );
setup_postdata( $post );
$my_uploaded_image = wp_get_attachment_image_src( $attachment_id );
$post_content = sprintf(
\'This post – %1$s is uploaded by %2$s on %3$s on category %4$s\',
get_the_title(),
get_the_author_meta( \'display_name\' );
get_the_date(),
get_the_category()
);
wp_reset_postdata()
return $post_content;
}
Note - 这将覆盖上一个
$post_content
. 如果您想添加,只需替换
$post_content = sprintf(
具有
$post_content.= sprintf(
.