Identifying the priority of style.css so I can make a small CSS file load last

When you properly enqueue a file, an instance of the wp_styles (more on this) class is created. The priority of actions is ignored. So it doesn’t matter if you write anything like add_action (‘wp_enqueue_scripts’,’function_adding_main_style’,10); add_action (‘wp_enqueue_scripts’,’function_adding_small_style’,11); The reason is exactly the existence of the dependency system. WP first collects all enqueued style files and then … Read more

WordPress Customizer Typography: How to load just the unique Google Fonts?

This question is way too broad for a complete answer in a Q&A format, but here is roughly what I would do: Collect all system fonts in an array $sys_fonts Collect all Google fonts in an array $ggl_fonts Collect the complete info about Google fonts in a multidimensional array $ggl_fontinfo Merge $sys_fonts and $ggl_fonts in … Read more

How to fix the error “file_get_contents was found in the file functions.php”?

To Add External Atylesheet: Generally speaking, you should use the wp_enqueue_style() function to add external stylesheet to your theme. function wpse259600_add_style() { wp_enqueue_style( ‘theme_critical’, get_template_directory_uri() . ‘/css/critical.css’, array(), ‘1.0.0’ ); } add_action( ‘wp_enqueue_scripts’, ‘wpse259600_add_style’ ); To Add Internal Stylesheet: However, if (for whatever reason) you have to add internal stylesheet (i.e. printing the entire CSS … Read more

Removing all classes from nav_menu except current-menu-item and current-menu-parent

Sure, you can filter out all the classes but the ones you want. add_filter(‘nav_menu_css_class’, ‘discard_menu_classes’, 10, 2); function discard_menu_classes($classes, $item) { $classes = array_filter( $classes, create_function( ‘$class’, ‘return in_array( $class, array( “current-menu-item”, “current-menu-parent” ) );’ ) ); return array_merge( $classes, (array)get_post_meta( $item->ID, ‘_menu_item_classes’, true ) ); }

How to Auto Approve Comments on a Specific Page?

Considering that in Settings > Discussion you have this options checked: The first is comment_moderation and the second comment_whitelist. Then, it is possible to selectively disable them using the filter pre_option_(option-name), as follows: add_filter( ‘pre_option_comment_moderation’, ‘wpse_72990_auto_aprove_selective’ ); add_filter( ‘pre_option_comment_whitelist’, ‘wpse_72990_auto_aprove_selective’ ); function wpse_72990_auto_aprove_selective( $option ) { global $post; if( $post->ID == 2 ) return 0; … Read more