Loading scripts with wp_register_script and wp_enqueue_script

There are probably various ways to do this – personally I use the following for loading some small scripts only on the “new” and “edit” pages (datepicker etc.): function load_my_admin_scripts( $hook ) { if (( $hook == ‘post.php’ || $hook == ‘post-new.php’ )) { wp_enqueue_script( ‘my-datepicker’, // name / handle of the script SCRIPTS . ‘script.js’, … Read more

Dynamic CSS Vs Inline Issues in Code any Way around in a WordPress Themes?

Well another solution would be to use wp_add_inline_style() which affords you an opportunity to inject dynamic inline styles: function my_custom_style() { wp_enqueue_style( ‘custom-style’, get_template_directory_uri() . ‘/css/custom-style.css’ ); //our customer percentage set by a user in some options panel $percentage = get_theme_mod(‘my-custom-percentage’); $inline_style =<<<DOC .progress-bar { width: {$percentage}%; } DOC; //inject our custom percentage after “custom-style.css” … Read more

Is It Always a Best Practice to Decouple the Frontend from the Admin Area When Developing a WordPress Application?

Off the top of my head I can’t think of any instance where you would want the WordPress admin to be the main entry point for your website, that there isn’t a more suitable software to use. Do you have a specific application or use in mind? In general I would say say, yes it … Read more

Is there any way to get all the name or slug of template parts used in a page?

You could filter the include paths returned by get_included_files by removing any files from the list that are not in your theme (and/or child theme) directory: function get_theme_includes() { $includedfiles = get_included_files(); // normalize theme paths for matching $styledir = str_replace(“\\”,”https://wordpress.stackexchange.com/”,get_stylesheet_directory()); $templatedir = str_replace(“\\”,”https://wordpress.stackexchange.com/”,get_template_directory()); $i = 0; // loop included files foreach ($includedfiles as $includedfile) … Read more