【问题标题】:Function not showing up in child theme WordPress子主题WordPress中未显示功能
【发布时间】:2015-08-07 17:17:28
【问题描述】:

我在 WordPress 的 Aaron 子主题中遇到了问题。我在Overwrite parent functions in child function.php WordPress 中回答了我的部分问题,但我无法让徽标以更大的尺寸工作。为了缩小范围并找到问题,我删除了很多代码。我发现子主题中的功能没有出现在 WordPress 中。这是函数:

/* Site Logo */
function add_site_icon_support() {
  $args = array(
    'header-text' => array(
      'Site Title Here',
      'Your site description goes here.',
    ),
    'size' => 'medium',
  );
  add_theme_support( 'site-logo', $args );
}
add_action( 'after_setup_theme', 'add_site_icon_support' );

我通过将它添加到父主题中的 functions.php 来测试它并且它可以工作。因此,我想知道如何使它在子主题中工作?

和父主题中的这个功能有关系吗?

function aaron_setup() {
  /*
   * Make theme available for translation.
   * Translations can be filed in the /languages/ directory.
   * If you're building a theme based on aaron, use a find and replace
   * to change 'aaron' to the name of your theme in all the template files
   */
  load_theme_textdomain('aaron', get_template_directory() . '/languages');
  // Add default posts and comments RSS feed links to head.
  add_theme_support('automatic-feed-links');
  add_theme_support('woocommerce');
  add_theme_support('jetpack-responsive-videos');
  add_editor_style();
  add_theme_support('post-thumbnails');
  add_image_size('aaron-featured-posts-thumb', 360, 300);
  add_theme_support('title-tag');
  register_nav_menus(array(
    'header' => __('Primary Menu', 'aaron'),
    'social' => __('Social Menu', 'aaron'),
  ));
  /*
   * Switch default core markup for search form, comment form, and comments
   * to output valid HTML5.
  */
  add_theme_support('html5', array('search-form', 'comment-form', 'comment-list', 'gallery', 'caption'));
}
endif; // aaron_setup
add_action('after_setup_theme', 'aaron_setup');

因为两者都有相同的钩子。

【问题讨论】:

  • 尝试在after_setup_theme钩子中设置较低的优先级。
  • 如果正确的功能存在于父主题而不是子主题中,它应该会自动工作。您的子主题中可能有一个 不同的 函数,它覆盖了父函数并且根本不应该存在。
  • @dda,感谢您编辑消息。

标签: php wordpress jetpack


【解决方案1】:

你需要在父主题之后运行你的钩子。您需要记住,首先加载子主题,然后加载父主题。

要使您的功能正常工作,您需要较低的优先级,即较高的数字。你可以试试

add_action( 'after_setup_theme', 'add_site_icon_support', 11 );

【讨论】:

  • 谢谢!有用。我一直在寻找整个互联网,只是找不到正确的答案......我确实阅读了一些关于加载子主题的文章,但没有关于优先级......只有 10 是默认数字或类似的东西。 ..
猜你喜欢
  • 2017-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-16
  • 2020-05-26
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
相关资源
最近更新 更多