Adding customizer styles with wp_add_inline_style

You can try to detect if the current used theme is a child and if so pointing the inline CSS to the right style. I didn’t tested this solution but could be a good starting point. function mytheme_enqueue_style() { wp_enqueue_style( ‘parent-theme-style’,get_template_directory_uri() . ‘/style.css’, false ); if(is_child_theme()) { wp_enqueue_style( ‘child-theme-style’, get_stylesheet_directory_uri() . ‘/style.css’, array(‘parent-theme-style’) ); } … Read more

How do I show sticky posts on a static front page that also contains content?

Something like this should work: $sticky = get_option( ‘sticky_posts’ ); if ( !empty( $sticky ) ) { // don’t show anything if there are no sticky posts $args = array( ‘posts_per_page’ => -1, // show all sticky posts ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) … Read more

Display a different theme for not logged-in users

Try hooking on all these: (But I guess you’d have to do it from a plugin, since doing it from theme functions.php might be too late). E.g.: /* Plugin Name: test Description: switchtest Version: 0.1.0 */ add_filter( ‘template’, ‘yourthing_switch_theme’ ); add_filter( ‘option_template’, ‘yourthing_switch_theme’ ); add_filter( ‘option_stylesheet’, ‘yourthing_switch_theme’ ); add_filter( ‘pre_option_stylesheet’, ‘yourthing_switch_theme’ ); function yourthing_switch_theme( $theme … Read more

How can I get wp_head() as a string instead of echoing it?

You can use PHP’s output buffering. WIth this you can write a wrapper for the get_head() function function wpse251841_wp_head() { ob_start(); wp_head(); return ob_get_clean(); } You can then use this as $data = array( ‘wpHead’ => wpse251841_wp_head(), ‘postContent’ => $post->post_content, ‘postContentFiltered’ => apply_filters( ‘the_content’, $post->post_content ) ); Reference: Output Control Functions

Enqueue scripts inside a class

You mean you call your class right before closing HTML tag? It is too late to enqueue scripts then. Don’t hook into wp_print_scripts to enqueue your scripts and styles. I just learned this today from Rarst. So change your init_hooks function to something like following: public function init_hooks() { add_action(‘wp_enqueue_scripts’, array(__CLASS__,’include_all_files’)); } Also you are … Read more

How to add default images for custom backgrounds?

if you are asking default background image for add_theme_support( ‘custom-background’); then it can be set using ‘default-image’ => get_template_directory_uri() . ‘/images/pattern.png’, complete code will look like below. $args = array( ‘default-color’ => ‘f0f0f0’, ‘default-repeat’ => ‘fixed’, ‘default-image’ => get_template_directory_uri() . ‘/assets/images/pattern.png’, ); add_theme_support( ‘custom-background’, $args );