Last active
October 15, 2024 18:11
-
-
Save taricco/00e11c8ee1af82eecd902977dd362ee4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** | |
| 1 - Find and replace cpt_name with CPT name using underscore | |
| 2 - Find and replace cpt-name with CPT name using a dash (if CPT name uses a dash) | |
| –––––––––––––––––––––––––––––––––––––––––––––––––– ***/ | |
| /* Load editor notice for CPT */ | |
| function wsv_cpt_name_notice_script() { | |
| // Ensure we are on the admin screen to prevent errors on the front end | |
| if (is_admin()) { | |
| // Get the current screen object | |
| $screen = get_current_screen(); | |
| // Check if the current screen is for the 'cpt-name' post type | |
| if ($screen->post_type == 'cpt-name') { | |
| // Get the path to the JS file | |
| $js_file_path = get_stylesheet_directory() . '/includes/99-custom/js/wsv_cpt_name_notice.js'; | |
| // Get the modified time of the file to use as the version | |
| $js_version = file_exists($js_file_path) ? filemtime($js_file_path) : '1.0.0'; | |
| // Enqueue the script with dynamic versioning | |
| wp_enqueue_script( | |
| 'wsv-cpt-name-notice', | |
| get_stylesheet_directory_uri() . '/includes/99-custom/js/wsv_cpt_name_notice.js', | |
| array(), // Dependencies, if any | |
| $js_version, // Version number based on file modification time | |
| true // Load in footer | |
| ); | |
| } | |
| } | |
| } | |
| add_action('enqueue_block_editor_assets', 'wsv_cpt_name_notice_script'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment