Skip to content

Instantly share code, notes, and snippets.

@shehabkhan013
Last active October 6, 2018 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shehabkhan013/c60da4226d276c2bd1e0923458b1f54e to your computer and use it in GitHub Desktop.
Save shehabkhan013/c60da4226d276c2bd1e0923458b1f54e to your computer and use it in GitHub Desktop.
CMB2 Post Format Interactivity Add
//includ the Js file is js folder
(function ($) {
$(document).ready(function () {
$("#post-formats-select .post-format").on("click", function () {
if ($(this).attr("id") == "post-format-image") {
$("#_alpha_image_information").show();
} else {
$("#_alpha_image_information").hide();
}
});
if (alpha_pf.format != "image") {
$("#_alpha_image_information").hide();
}
});
})(jQuery);
// 1st this function add functions.php file
function alpha_admin_assets( $hook ) {
if ( isset( $_REQUEST['post'] ) || isset( $_REQUEST['post_ID'] ) ) {
$post_id = empty( $_REQUEST['post_ID'] ) ? $_REQUEST['post'] : $_REQUEST['post_ID'];
}
if ( "post.php" == $hook ) {
$post_format = get_post_format($post_id);
wp_enqueue_script( "admin-js", get_theme_file_uri( "/assets/js/admin.js" ), array( "jquery" ), VERSION, true );
wp_localize_script("admin-js","alpha_pf",array("format"=>$post_format));
}
}
add_action( "admin_enqueue_scripts", "alpha_admin_assets" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment