Last active
December 23, 2023 15:35
-
-
Save nextab/480840131e18653a7cdd47c0f901042d 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
| function nxt_load_dynamically() { | |
| $tempContent = get_the_content(); | |
| $tempCheck = '[nxt_application'; | |
| $tempVerify = strpos($tempContent,$tempCheck); | |
| if($tempVerify === false) { | |
| // Dein Code, wenn die Nadel im Heuhaufen NICHT gefunden wurde | |
| } else { | |
| // Dein Code, WENN die Nadel GEFUNDEN wurde, z. B. | |
| acf_form_head(); | |
| wp_enqueue_style('mein-style'); | |
| } | |
| } | |
| add_action('wp_head', 'nxt_load_dynamically', 1); | |
| /* Zweites Beispiel: Diesmal wird gecheckt, ob eine Klasse für ein bestimmtes Formular im Quellcode vorhanden ist (unabhängig von der Präsenz eines Shortcodes) */ | |
| // Enqueue the script on the booking page | |
| function dynamic_enqueue_script() { | |
| if (!is_page()) return; // leave this only in if you are certain that you will only need this script on a page | |
| global $post; | |
| if (strpos($post->post_content, 'zmmt_event_orders') === false) return; | |
| wp_register_script('my-script', plugin_dir_url(__FILE__) . 'js/my-script.js', ['my-dependency'], '1.0', true); | |
| // Localize the script with your data | |
| wp_enqueue_script('my-script'); | |
| } | |
| add_action('wp_enqueue_scripts', 'dynamic_enqueue_script', 9999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment