How to remove TwentyTwelve style while creating child theme?


It is general process to remove style of parent theme while creating child theme for any WordPress themes.  In the same way, recently I tried to dequeue style of TwentyTwelve WordPress theme.  But it did not work.

After Googling and with lots of trials and errors, I found that the style needs to be deregistered too.

The following code helped me better in creating child theme for TwentyTwelve WordPress theme.

function ajaxipage_styles() {
		wp_dequeue_style( 'twentytwelve-style' );
		wp_deregister_style( 'twentytwelve-style' );
		wp_enqueue_style( 'twentytwelve-style-2', get_template_directory_uri() . '/style.css' );
		wp_enqueue_style( 'ajaxipage-style', get_stylesheet_directory_uri() . '/style.css' );
	add_action( 'wp_enqueue_scripts', 'ajaxipage_styles', 20 );

This code has to be written in the functions.php of child theme.  The code works in the following way,

  1. First it dequeues the twentytwelve style.
  2. Then it deregisters the same.
  3. Now We are invoking the same twentytwelve theme style in another id called “twentytwelve-style-2”.
  4. After that, we call our own stylesheet of child theme.

The value “20” in add_action gives priority.  I hope it is useful to some developers.

Leave a comment