简体   繁体   English

通过子主题函数向PHP插件自定义帖子类型添加选项

[英]Add options to a Wordpress plugin Custom Post Type via child theme functions.php

I'm using Uncode theme for a site. 我正在为网站使用Uncode主题。 It has a core custom post type called 'portfolio'. 它具有一个称为“ portfolio”的核心自定义帖子类型。

I need to add an option to this CPT so that it shares the tags with regular posts. 我需要为此CPT添加一个选项,以便它与常规帖子共享标签。

I have found the file in the theme core where the CPT is registered and added the following and it works: 我已经在注册了CPT的主题核心中找到了该文件,并添加了以下内容并且可以正常工作:

'taxonomies' => array('portfolio_category', 'post_tag')

However, as editing core files is a big no no, I'm wondering if there is a way of doing this through my own functions file so it is future proof? 但是,由于编辑核心文件是一件很重要的事,我想知道是否有一种方法可以通过我自己的函数文件来做到这一点,所以它可以用于未来吗?

EDIT : It's apparent that I've misunderstood! 编辑 :显然我误解了!

Looks like register_taxonomy_for_object_type is what you're after. 看起来您想要的是register_taxonomy_for_object_type

The WP Codex has this to say: WP法典有这样的说法:

register_taxonomy_for_object_type() register_taxonomy_for_object_type()

Add a registered Taxonomy to a registered Post Type. 将注册分类法添加到注册帖子类型。

register_taxonomy_for_object_type( 'post_tag', 'portfolio' );

Original answer: 原始答案:

From the WP Codex : WP Codex

register_post_type() register_post_type()

Create or modify a post type. 创建或修改帖子类型。 register_post_type should only be invoked through the 'init' action. register_post_type仅应通过'init'操作来调用。 It will not work if called before 'init' , and aspects of the newly created or modified post type will work incorrectly if called later. 如果在'init'之前调用,它将不起作用,如果稍后调用,则新创建或修改的帖子类型的各个方面将无法正常工作。

(addtl. emphasis mine) (另外强调我的)

This being the case, you could create a function 在这种情况下,您可以创建一个函数

function igloobob_portfolio_cpt_mod() {
    register_post_type('portfolio', $args);
}
add_action('init', 'igloobob_portfolio_cpt_mod', 999);

where $args basically duplicate's the Uncode theme's arguments to register_post_type , save for your modification. $args基本上将Uncode主题的参数复制到register_post_type ,并保存您的修改。 The 999 priority arg is to ensure that it executes after the parent theme has already registered the post type. 999优先级arg是为了确保它在父主题已经注册了帖子类型之后执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在WordPress子主题中的functions.php上添加多个脚本? - How to add multiple script on functions.php in wordpress child theme? 如何在Wordpress子主题functions.php中正确排队retina.js? - How do I enqueue retina.js in a Wordpress child theme functions.php properly? Javascript和Wordpress:子主题的Functions.php,用于更改JS文件上的值 - Javascript and Wordpress: Functions.php for a child theme to change a value on a JS file 在Wordpress中将自定义javascript添加到functions.php - Adding custom javascript to functions.php in wordpress 使用functions.php文件在wordpress主题中包含javascript文件 - include javascript files in wordpress theme using functions.php file 通过 javascript 将自定义 CSS 添加到 wordpress 中的第三方插件。ZE1BFD762321E40963CEE4AC0B6E841 - Adding custom CSS to third party plugin in wordpress through javascript from functions.php 通过functions.php向Wordpress中的Body添加固定ID - Adding a fixed ID to Body in Wordpress via functions.php jQuery 转换为 Wordpress 函数。php - jQuery into Wordpress functions.php 使用wp_enqueue_script()在Wordpress-functions.php中添加Javascript - Add Javascript in Wordpress - functions.php with wp_enqueue_script() 如何在 WordPress 函数.php 上添加 datalayer.push? - How to add datalayer.push on WordPress functions.php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM