【问题标题】:How to hide Permalink section from a Custom Post Type's post?如何从自定义帖子类型的帖子中隐藏固定链接部分?
【发布时间】:2015-04-26 02:55:45
【问题描述】:

我想在 Wordpress 中隐藏特定帖子类型的帖子标题下的永久链接部分。我该怎么做?

【问题讨论】:

    标签: wordpress custom-post-type permalinks posts


    【解决方案1】:

    register_post_types 下添加以下参数:

    'public' => false,  // it's not public, it shouldn't have it's own permalink, and so on
    'publicly_queryable' => true,  // you should be able to query it
    'show_ui' => true,  // you should be able to edit it in wp-admin
    'exclude_from_search' => true,  // you should exclude it from search results
    'show_in_nav_menus' => false,  // you shouldn't be able to add it to menus
    'has_archive' => false,  // it shouldn't have archive page
    'rewrite' => false,  // it shouldn't have rewrite rules
    

    你需要的是第一个元素'public' => false

    【讨论】:

    • 在某些情况下,我们需要将自定义帖子类型保持为 true
    • 我同意,但根据问题,这是实际隐藏永久链接的正确方法。这真的取决于你想在 WP 中实现什么以及如何实现
    【解决方案2】:

    我们找不到这样的过滤器或选项来删除“标题”“内容编辑器”等“slug”。

    我们需要通过 CSS 来管理它。通过研究高级自定义字段(ACF),他们做同样的事情。 他们将 display:none 放在代码中。

    您只需将以下代码放在您的 style.css 中:

    .post-type-<post type slug> #edit-slug-box {
    display: none;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-28
      • 1970-01-01
      • 2012-01-01
      • 1970-01-01
      • 2012-11-13
      • 2023-03-28
      • 2016-03-28
      • 2023-03-30
      相关资源
      最近更新 更多