php - 元素临 : Change or remove category/tag/author prefix from Archive Title

标签 php wordpress elementor

我正在使用 Elementor Pro 构建我的页面模板,并且我使用以下功能将标签标签更改为“主题”——这在任何地方都有效,除了 Elementor Archive Title 小部件(通过常规 Title 小部件制作)将动态标签设置为“存档标题”)。

以下是我将标签更改为主题的函数:

      // Change tags to topics

function wd_hierarchical_tags_register() {

  // Maintain the built-in rewrite functionality of WordPress tags

  global $wp_rewrite;

  $rewrite =  array(
    'hierarchical'              => false, // Maintains tag permalink structure
    'slug'                      => get_option('tag_base') ? get_option('tag_base') : 'tag',
    'with_front'                => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
    'ep_mask'                   => EP_TAGS,
  );

// Redefine tag labels (or leave them the same)
    
      $labels = array(
        'name'                       => _x( 'Topics', 'Taxonomy General Name', 'hierarchical_tags' ),
        'singular_name'              => _x( 'Topic', 'Taxonomy Singular Name', 'hierarchical_tags' ),
        'menu_name'                  => __( 'Topics', 'hierarchical_tags' ),
        'all_items'                  => __( 'All Topics', 'hierarchical_tags' ),
        'parent_item'                => __( 'Parent Topic', 'hierarchical_tags' ),
        'parent_item_colon'          => __( 'Parent Topic:', 'hierarchical_tags' ),
        'new_item_name'              => __( 'New Topic Name', 'hierarchical_tags' ),
        'add_new_item'               => __( 'Add New Topic', 'hierarchical_tags' ),
        'edit_item'                  => __( 'Edit Topic', 'hierarchical_tags' ),
        'update_item'                => __( 'Update Topic', 'hierarchical_tags' ),
        'view_item'                  => __( 'View Topic', 'hierarchical_tags' ),
        'separate_items_with_commas' => __( 'Separate topics with commas', 'hierarchical_tags' ),
        'add_or_remove_items'        => __( 'Add or remove topics', 'hierarchical_tags' ),
        'choose_from_most_used'      => __( 'Choose from the most used', 'hierarchical_tags' ),
        'popular_items'              => __( 'Popular Topics', 'hierarchical_tags' ),
        'search_items'               => __( 'Search Topics', 'hierarchical_tags' ),
        'not_found'                  => __( 'Not Found', 'hierarchical_tags' ),
      );
    
      // Override structure of built-in WordPress tags
    
      register_taxonomy( 'post_tag', 'post', array(
        'hierarchical'              => true, // Was false, now set to true
        'query_var'                 => 'tag',
        'labels'                    => $labels,
        'rewrite'                   => $rewrite,
        'public'                    => true,
        'show_ui'                   => true,
        'show_admin_column'         => true,
        '_builtin'                  => true,
      ) );
    
    }
    add_action('init', 'wd_hierarchical_tags_register');
    

尽管有上面的代码,我仍然看到“标签”作为前缀 on archive pages .我也试过从存档标题中删除前缀,但这对 Elementor 标题小部件也没有影响。

    // Remove default labels from archive title

    add_filter( 'get_the_archive_title', function ($title) {
    if ( is_category() ) {
            $title = single_cat_title( '', false );
        } elseif ( is_tag() ) {
            $title = single_topic_title( '', false );
        } elseif ( is_author() ) {
            $title = '<span class="vcard">' . get_the_author() . '</span>' ;
        } 
    return $title;
});

如有任何帮助,我们将不胜感激。如果我可以将标签更改为存档标题上的主题,或者从存档标题中完全删除“标签:”前缀(我也可以删除作者/类别/月/年),我会很高兴。

最佳答案

在 Elementor 中,您可以在“存档标题”元素设置中控制此前缀的可见性。单击小 Spanner 图标并取消选中“包含上下文”选项。

关于php - 元素临 : Change or remove category/tag/author prefix from Archive Title,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64901806/

相关文章:

php - 如何为 Google Place 的 "Reviews by Google Users"构建站点小部件/模块

javascript - 如果输入了最低价格,如何使最高价格成为必需?

php - 从电子邮件通知模板中删除客户详细信息和地址

wordpress - 在元素或表单中单击按钮时隐藏/取消隐藏部分

wordpress - 如何在 wordpress docker 镜像上安装 PHP Extensionson SourceGuardian?

php - 带有空格的 if 子句中出现意外的 T_STRING

php - 如何从两个表中获取结果? (MySQLi)

php - 尝试输出时调用未定义函数 session_unregister()

wordpress - 如何修复wordpress中的评论模板?

css - 如何使用图标列表元素或模块将图标对齐到文本的右侧?