钩子文档

shortcut_link

💡 云策文档标注

概述

shortcut_link 是一个 WordPress 过滤器,用于修改 Press This 书签工具的链接。该过滤器在 WordPress 4.9.0 版本中已被弃用。

关键要点

  • shortcut_link 过滤器允许开发者自定义 Press This 书签工具的链接。
  • 过滤器接受一个参数 $link,表示原始的 Press This 书签工具链接字符串。
  • 此过滤器在 WordPress 4.9.0 版本中已弃用,建议使用替代方法。
  • 相关函数 get_shortcut_link() 用于检索 Press This 书签工具链接,位于 wp-includes/deprecated.php 文件中。

代码示例

add_filter('shortcut_link', 'press_this_ptype', 11);

function press_this_ptype($link) {
	$post_type = 'example';

	$link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link);
	$link = str_replace('?u=', '&u;=', $link);

	return $link;
}

注意事项

由于 shortcut_link 过滤器已被弃用,开发者应避免在新项目中使用,并考虑迁移到其他方法。


📄 原文内容

Filters the Press This bookmarklet link.

Parameters

$linkstring
The Press This bookmarklet link.

Source

return apply_filters( 'shortcut_link', $link );

Changelog

Version Description
4.9.0 Deprecated.
2.6.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Example migrated from Codex:

    Create a “Press This” button for a custom post type called example.

    add_filter('shortcut_link', 'press_this_ptype', 11);
    
    function press_this_ptype($link) {
    	$post_type = 'example';
    
    	$link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link);
    	$link = str_replace('?u=', '&u;=', $link);
    
    	return $link;
    }