Home>Support>Add Custom Post Type Support After Activating the Page Builder Plugin

Add Custom Post Type Support After Activating the Page Builder Plugin

Hi,

I’m developing my new theme. And I integrate my theme with SiteOrigin Page Builder with TGM Plugin Activation.
I have one custom post type.

My question is, how can I add page builder plugin to my new custom post type without changing on the settings page.

Maybe is there any way to add action and set my custom post slug as a Page Builder support?

Thank you

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Imam,

    You can do this with SiteOrigin_Panels_Settings::single()->set(‘post-types’, $values).

    Set will replace what is currently set so be sure to get the old value with get() and merge your post type with that.

  2. 8 years, 1 month ago imam

    Hi Alex,

    Thank you for answering my question.

    I don’t understand with your answer, I think above implementation is using PHP Class, right?

    Can you show me step by step how to add that code? Should I place that code in my Theme functions.php?

    Thank you

  3. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Imam,

    I can’t really help you with providing exact code but I can however answer your questions.

    Yes, it’s a class. I would recommend clicking the links I posted as that’ll show you the exact code.

    This will give you an idea of the structure of the post types and give you an idea of how to add it.

    function test_action(){	var_dump(SiteOrigin_Panels_Settings::single()->get('post-types'));}add_action('init', 'test_action', 15);

    Please add that your themes functions.php (or a separate file if desired). Also, please remove the var_dump to prevent it from dumping the row.

  4. 8 years, 1 month ago imam

    Hi, Alex

    Thank you for your explanation.
    My code is working well.

    function superpower_superpageinit(){
    	SiteOrigin_Panels_Settings::single()->get( 'post-types' );
    	$post_types	= array( 'post', 'page', 'superpage' );
    	SiteOrigin_Panels_Settings::single()->set( 'post-types', $post_types );
    }
    add_action('init', 'superpower_superpageinit', 15);
    

    Is that right?
    I have tested it and it’s working.

    Thank you Alex :)

  5. 8 years, 1 month ago Alex S
    Hi, I Work Here

    Hi Imam,

    No, that’s not right. You’re getting the currently active post types and not doing anything them. Instead you’re enabling the post, page and superpage post types and completely disregarding what the user is currently using. Based on this setup, it’s impossible to enable a different post type.

    Use this:

    function superpower_superpageinit(){
    	$post_types = SiteOrigin_Panels_Settings::single()->get( 'post-types' );
    	$post_types[] = 'superpage';
    	SiteOrigin_Panels_Settings::single()->set( 'post-types', $post_types );
    }
    add_action('init', 'superpower_superpageinit', 15);
    

    I should have suggested a different hook as currently this hook is run on every page load, which isn’t necessary due to it being stored. I would recommend adding this code to your register_activation_hook. It’ll run once (when the plugin has activated) and then won’t run again. This is overall much better.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More