Support » Fixing WordPress » Can you get the themes options page to turn on/off which custom post types are r

  • Resolved think.different


    I have a theme that is being used for a multisite installation that will be used by 6 sub-brands of an organization. Each sub-brand will only require some of the custom post types set up by the theme – thus I would like to hide the ones not needed.

    The theme has an options page where I can set a variable to state which brand is using the theme. I then want the functions.php to check what the variable has been set and then register the relevant post types.

    eg. If the brandX then register post types A & C, if brandY then register post type B, if BrandC then register none.

    Here is what I have done so far, the theme is a purchased theme so I’m having to hack around with what has already be written. Within the theme-options.php after I set up the “brand” option I have added:

    global $brandChoice;
    $brandChoice = $data['brand_choice'];

    I have echoed $brandChoice into the header.php and the function.php and it will display that variable front & back end plus it will change as I change the brand to another brand.

    The next bit of code doesn’t seem to work:

    add_action( 'admin_init', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
    	global $brandChoice;
      	echo 'Variable: '.$brandChoice;  //This displays correct brand name at the top of the page
      	if ( $brandChoice == 'option1' ) {
      		register_post_type( 'nameHere', array( //etc
Viewing 2 replies - 1 through 2 (of 2 total)
  • okay so the if statement is working, it’s just not doing the register_post_type bit from within the if statement?

    Right I have come at this from a different angle. I registered all the posts as normal. And then depending of the variable set it will remove the menu from the backend.

    function remove_menu_items() {
        global $brandChoice;
        if ( $brandChoice == 'brand1' ) {
            remove_menu_page( 'edit.php?post_type=cpt1' );
        } else if ( $brandChoice == 'brand2' ) {
            remove_menu_page( 'edit.php?post_type=cpt2' );
        } else {
            // something else
    add_action( 'admin_menu', 'remove_menu_items' );

    This is now working as I hoped, As I change the brand in the brand variable in the themes options and then load any other backend page the menu structure changes to only show the CPT I want to see.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can you get the themes options page to turn on/off which custom post types are r’ is closed to new replies.