privacy_on_link_title
云策文档标注
概述
privacy_on_link_title 是一个 WordPress 过滤器,用于修改‘At a Glance’仪表板小部件中‘Search engines discouraged’消息的链接标题属性。该过滤器允许开发者自定义链接标题文本,例如添加前缀或修改内容。
关键要点
- 过滤器名称:privacy_on_link_title,用于过滤链接标题属性。
- 参数:$title(字符串),默认值为空字符串,表示默认的标题文本。
- 用途:在‘At a Glance’仪表板小部件中,针对‘Search engines discouraged’消息的链接标题进行自定义。
- 历史:在 WordPress 3.0.0 中引入,4.5.0 版本将 $title 默认值更新为空字符串。
- 相关函数:wp_dashboard_right_now() 用于显示仪表板小部件的基本站点统计信息。
代码示例
function wpdocs_modify_privacy_on_link_title_defaults( $title ) {
if ( strpos( $title, 'Privacy' ) !== false ) {
$title = 'Modified: ' . $title;
}
return $title;
}
add_filter( 'privacy_on_link_title', 'wpdocs_modify_privacy_on_link_title_defaults' );注意事项
- 使用前需确保理解过滤器的作用域,避免影响其他功能。
- 示例代码展示了如何添加和移除过滤器,开发者可根据实际需求调整。
- 注意版本兼容性,默认值在 4.5.0 版本后变为空字符串。
原文内容
Filters the link title attribute for the ‘Search engines discouraged’ message displayed in the ‘At a Glance’ dashboard widget.
Description
Prior to 3.8.0, the widget was named ‘Right Now’.
Parameters
$titlestring-
Default attribute text.
Source
$title = apply_filters( 'privacy_on_link_title', '' );
Skip to note 2 content
Noruzzaman
We will create a function that modifies link titles containing the word “Privacy” by prefixing them with “Modified: “. We will use WordPress filters to achieve this.
Step 1: Define the Function
function wpdocs_modify_privacy_on_link_title_defaults( $title ) { // Check if the title contains the word 'Privacy' if ( strpos( $title, 'Privacy' ) !== false ) { // Modify the title $title = 'Modified: ' . $title; } return $title; } // Add the filter add_filter( 'privacy_on_link_title', 'wpdocs_modify_privacy_on_link_title_defaults' );Step 2: Apply the Filter for Demonstration
// For demonstration, we'll use the filter on a sample link title $sample_title = __( 'Privacy Policy' ); $modified_title = apply_filters( 'wpdocs_privacy_on_link_title', $sample_title ); // Output the result for demonstration purposes echo $modified_title; // This should output "Modified: Privacy Policy"Step 3: Remove the Filter (Optional)
// Remove the filter if you no longer need it remove_filter( 'privacy_on_link_title", 'wpdocs_modify_privacy_on_link_title_defaults' );