首页 问答 正文

如何为wordpress主题添加友情链接功能?

注册会员 / 悠然自学 / 2023-07-11/ 浏览 130 次

为WordPress主题添加友情链接功能可以通过以下步骤实现:

  1. 打开主题的functions.php文件,通常位于主题的根目录下,找到以下代码:
    add_action('after_setup_theme', 'theme_setup');
    function theme_setup(){
    // 添加其他主题设置代码
    } 
  2. 在以上代码后面添加以下代码:
    // 添加友情链接功能
    add_filter('pre_option_link_manager_enabled', '__return_true'); 
  3. 保存并关闭functions.php文件。

在WordPress后台的‘外观’->‘小工具’中,将会看到一个名为‘链接’的小工具,将它添加到你希望显示友情链接的侧边栏,然后就可以在WordPress后台的‘链接’->‘链接’中添加、编辑和管理友情链接了。

注意:如果你的主题已经有侧边栏支持,并且在侧边栏中已经添加了其他小工具,友情链接小工具可能就已经自动显示在侧边栏中了,无需进一步操作。

示例代码:

add_action('after_setup_theme', 'theme_setup');
function theme_setup(){
  // 添加其他主题设置代码

  // 添加友情链接功能
  add_filter('pre_option_link_manager_enabled', '__return_true');
} 

这样就为WordPress主题添加了友情链接功能。

大家谈论
    我的见解