Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

##Activating Your Preferred Theme Activating a theme is a bit easier than deleting or activating a plugin, comparatively speaking; one function call is all that is required: switch_theme(). The switch_theme() function accepts two (2) parameters: the template and the stylesheet. Well, at least that's what the parameters are named. You might be more familiar with the terms Parent Theme and Child ThemeParent Theme and Child Theme.

##Activating Your Preferred Theme Activating a theme is a bit easier than deleting or activating a plugin, comparatively speaking; one function call is all that is required: switch_theme(). The switch_theme() function accepts two (2) parameters: the template and the stylesheet. Well, at least that's what the parameters are named. You might be more familiar with the terms Parent Theme and Child Theme.

##Activating Your Preferred Theme Activating a theme is a bit easier than deleting or activating a plugin, comparatively speaking; one function call is all that is required: switch_theme(). The switch_theme() function accepts two (2) parameters: the template and the stylesheet. Well, at least that's what the parameters are named. You might be more familiar with the terms Parent Theme and Child Theme.

Removed incorrect formatting.
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132

##Deleting the "Hello World" Post Next we want to delete the "Hello World" post. You may have seen that @Rarst has shown us how to use the wp_delete_post() function which is exactly what we need. As he explained the second parameter will fully delete the post as opposed to moving it to the trash and the first parameter is the $post->ID.

Of course it would be nice to be able to specify the slug instead of the $post->ID and so I decide to find a way to do that. After some spelunking I found that WordPress has an unfortunately named function called get_page_by_path() which actually allows us to look up any post type by its slug (it is unfortunately named because you might overlook it when trying to find something that works with post types other than 'page'.)

Since we passing get_page_by_path() the WordPress-defined constant OBJECT it will return to us a post in the form of an post object. For the third parameter we passed 'post' to indicate we wanted it to lookup post types of 'post'. Since get_page_by_path() will return the post object we need or return null if no post matches the slug we can check for existence and do a lookup at the same time:

$post = get_page_by_path('hello-world',OBJECT,'post');
if ($post)
  wp_delete_post($post->ID,true);

Note: We could have run code to delete every post in the database but if we had we would not be able to run this code again once we've added the posts we want to keep and that was one of our design constraints.

##Deleting the "Hello World" Post Next we want to delete the "Hello World" post. You may have seen that @Rarst has shown us how to use the wp_delete_post() function which is exactly what we need. As he explained the second parameter will fully delete the post as opposed to moving it to the trash and the first parameter is the $post->ID.

Of course it would be nice to be able to specify the slug instead of the $post->ID and so I decide to find a way to do that. After some spelunking I found that WordPress has an unfortunately named function called get_page_by_path() which actually allows us to look up any post type by its slug (it is unfortunately named because you might overlook it when trying to find something that works with post types other than 'page'.)

Since we passing get_page_by_path() the WordPress-defined constant OBJECT it will return to us a post in the form of an post object. For the third parameter we passed 'post' to indicate we wanted it to lookup post types of 'post'. Since get_page_by_path() will return the post object we need or return null if no post matches the slug we can check for existence and do a lookup at the same time:

$post = get_page_by_path('hello-world',OBJECT,'post');
if ($post)
  wp_delete_post($post->ID,true);

Note: We could have run code to delete every post in the database but if we had we would not be able to run this code again once we've added the posts we want to keep and that was one of our design constraints.

Clarified directory slug/theme identifier
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132

But what if it is not a child theme? That's easy, just pass the directory slug/theme identifier (i.e. the name of subdirectory off of /wp-content/themes that contains your theme) as both parameters. Assuming you want to activate the Thematic theme by Ian D Stewart you've call switch_theme() like so:

One key point to be aware of; the get_theme() function expects to be passed the name of the Child Theme, NOT it's directory slug/theme identifier. (The name comes from the "Theme Name:" section in the header of the theme's style.css file. Fortunately the get_current_theme() function returns the name too.)

But what if it is not a child theme? That's easy, just pass the theme identifier (i.e. the name of subdirectory off of /wp-content/themes that contains your theme) as both parameters. Assuming you want to activate the Thematic theme by Ian D Stewart you've call switch_theme() like so:

One key point to be aware of; the get_theme() function expects to be passed the name of the Child Theme, NOT it's directory slug. (The name comes from the "Theme Name:" section in the header of the theme's style.css file. Fortunately the get_current_theme() function returns the name too.)

But what if it is not a child theme? That's easy, just pass the directory slug/theme identifier (i.e. the name of subdirectory off of /wp-content/themes that contains your theme) as both parameters. Assuming you want to activate the Thematic theme by Ian D Stewart you've call switch_theme() like so:

One key point to be aware of; the get_theme() function expects to be passed the name of the Child Theme, NOT it's directory slug/theme identifier. (The name comes from the "Theme Name:" section in the header of the theme's style.css file. Fortunately the get_current_theme() function returns the name too.)

Added Activating Your Preferred Theme section
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
Loading
Added Activating Our Plugins
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
Loading
Added Deleting the "Hello Dolly" Plugin section
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
Loading
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
Loading