Archives Code Snippets

cmb2 shortcode field

// This is how you add a CMB2 field per the CMB2 docs $cmb->add_field( array( ‘name’ => ‘Test File’, ‘desc’ => ‘Upload an image or enter an URL.’, ‘id’ => ‘my_custom_test_image’, ‘type’ => ‘file’, // Optionally hide the text input…

shortcode enqueue

function my_custom_shortcode_enqueue() { wp_register_style( ‘my_shortcode_css’, ‘plugin-dir’ ); wp_register_script( ‘my_shortcode_js’, ‘plugin-dir’ ); } add_action( ‘wp_enqueue_scripts’, ‘my_custom_shortcode_enqueue’ );

shortcode callback

function my_custom_shortcode() { $shortcode = array( ‘id’ => ‘my_custom_shortcode’, // make this unique ‘name’ => ‘My Custom’, // name in modal drop down ‘template’ => ‘posts’, // name of the shortcode template ‘template_location’ => ‘plugin-dir/my-templates’, // path to template folder…

cptui_register_shortcode()

function my_custom_cptui_shortcode() { cptui_register_shortcode( ‘my_custom_shortcode’ ); cptui_register_shortcode( ‘my_custom_page_shortcode’ ); cptui_register_shortcode( ‘my_custom_single_post_shortcode’ ); } add_action( ‘cptuiext_loaded’, ‘my_custom_cptui_shortcode’ );