I've got a WP Network. In the network I have a custom post type for an agenda. I only want to let it show up in the main/primary site/network. I've tried to is_main_network()
in init
. But it returns true
on every site. (Is this approach too soon in init?)
Or in other words, how would I enqueue a new custom post type only in the primary network site?
This is my current code that does not work:
add_action( 'init', function () {
if ( is_main_network() ) {
$args = ...
register_post_type( "agenda", $args );
}
} );
CodePudding user response:
According to docs, this will return bool if your on main site: https://developer.wordpress.org/reference/functions/is_main_site/
add_action( 'init', function () {
if ( is_main_site() ) {
$args = ...
register_post_type( "agenda", $args );
}
} );