admin管理员组文章数量:1124017
I am trying to add some HTML to the title label in the backend of WordPress.
Attempt 1:
I am using the following (simplified) function:
function change_post_titles() {
global $post, $title, $action, $current_screen;
$title = 'foo<br>bar';
}
add_action('admin_head', 'change_post_titles');
This works in the way that the label of the title field is indeed changed, however the HTML tags get encoded afterwards. This mean that the label looks like:
foo<br>bar
Instead of:
foo
bar
Attempt 2:
I also tried using a gettext
filter, but that just completely filters (removes) the HTML.
add_filter('gettext', 'change_post_titles');
function change_post_titles( $translated_text, $text, $domain ) {
return $translated_text = 'foo<br>bar';
}
Is there any way to change the title label (programmatically) in a way I can add HTML?
I am trying to add some HTML to the title label in the backend of WordPress.
Attempt 1:
I am using the following (simplified) function:
function change_post_titles() {
global $post, $title, $action, $current_screen;
$title = 'foo<br>bar';
}
add_action('admin_head', 'change_post_titles');
This works in the way that the label of the title field is indeed changed, however the HTML tags get encoded afterwards. This mean that the label looks like:
foo<br>bar
Instead of:
foo
bar
Attempt 2:
I also tried using a gettext
filter, but that just completely filters (removes) the HTML.
add_filter('gettext', 'change_post_titles');
function change_post_titles( $translated_text, $text, $domain ) {
return $translated_text = 'foo<br>bar';
}
Is there any way to change the title label (programmatically) in a way I can add HTML?
Share Improve this question edited Jul 29, 2014 at 15:37 user6669 asked Jul 25, 2014 at 11:43 user6669user6669 711 silver badge3 bronze badges 1 |2 Answers
Reset to default 1It is not possible to add HTML to it.
For example, wp-admin/edit.php
uses the following code:
<h1 class="wp-heading-inline">
<?php
echo esc_html( $post_type_object->labels->name );
?>
</h1>
As you can see, this uses the esc_html() function. This prevents you from adding html code. This works this way for security reasons.
function change_post_titles() {
global $post, $title, $action, $current_screen;
$title = "foo<br>bar";
$title = str_replace('<br>', ' ', $title);
}
add_action('admin_head', 'change_post_titles');
Use this this will give the result you want. Please check it let me know for any doubts.
本文标签:
版权声明:本文标题:wp admin - Change label of title field for posts in the backend 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736600606a1945212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp-admin/*.php
foradd-new-h2
(the class of the button afterwards) you'll see that the pages that use the title always render it asecho esc_html( $title );
. – Rup Commented Jul 29, 2014 at 17:37