首页 > 解决方案 > 如何在 Wordpress 中为评论字段使用动态占位符文本

问题描述

我有一个自定义字段,我想在评论字段的文本区域中将其用作占位符文本,但我不确定如何将其正确插入代码中。感谢您的帮助!

Functions.php 代码:

function sabretooth_textarea_placeholder( $fields ) {
    $fields['comment_field'] = str_replace(
        '<textarea',
        '<textarea placeholder="Comment field placeholder text here please"',
        $fields['comment_field']
    );

自定义字段代码:

get_field('comment_field_placeholder', pll_get_post(881));

标签: phpwordpress

解决方案


自己解决了:)

function sabretooth_textarea_placeholder( $fields ) {
    $comment_placeholder = get_field('comment_field_placeholder', pll_get_post(881));
    $fields['comment_field'] = str_replace(
        '<textarea',
        '<textarea placeholder="' . $comment_placeholder . '"',
        $fields['comment_field']
    );

推荐阅读