简体   繁体   中英

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

I'm using Uncode theme for a site. It has a core custom post type called 'portfolio'.

I need to add an option to this CPT so that it shares the tags with regular posts.

I have found the file in the theme core where the CPT is registered and added the following and it works:

'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.

The WP Codex has this to say:

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 :

register_post_type()

Create or modify a post type. register_post_type should only be invoked through the 'init' action. It will not work if called before 'init' , and aspects of the newly created or modified post type will work incorrectly if called later.

(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. The 999 priority arg is to ensure that it executes after the parent theme has already registered the post type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM