php - 如何在 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));
解决方案
自己解决了:)
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']
);
推荐阅读
- html - 如何在 ac# web 表单中对齐标签
- javascript - 如何先隐藏 Div 然后在选择选项后显示
- python - 如何使用分类和连续变量作为 scikit 逻辑回归算法的输入
- ios - 让 AuthListener 等到 for 循环完成
- linux - 有谁知道如何在 Visual Studio Code 中重置 gitlens 扩展的身份验证
- python - 如何获得日志丢失?
- sql - 如果“GROUP BY”字段中的任何数据元素为 NULL,如何返回 NULL?
- javascript - 如何根据上次使用的变体将用户重定向到不同的网站变体?
- vb.net - 如何在 Windows 窗体应用程序(Visual Studio,VB.Net)中将焦点设置在 ComboBox 上?
- c# - 设置 document.table 实例的单元格或文本对齐方式