I need to automatically (without anything visible to the user in the UI and without user intervention) 'mark' a post in a sub-blog with the theme it was set to when the user posted.

As I understand it I have to use wp_insert_term() once to insert this new term 'uses-theme' into the terms table in the database.

Then I have to add an action containing wp_set_post_terms() (with the value of get_current_theme()), to some core function that is executed when a post is created or saved.

I don't have access to the core .php files, so I'm looking for some way of adding this to the functions.php.

If it's easier to automatically tag or categorize, I will do that. I just don't know how to hook it in.

UPDATE: I just realized I get the blogid in the post meta. If I could look up the stylesheet_directory or similar "bloginfo" field from the database, the problem would be solved. But I'm looking at the blogs table, and it doesn't have those bloginfo fields - and get_bloginfo() only returns info about the CURRENT blog.

If I knew how to look up stylesheet information from the blog id, I would be home! How?

  • Have you considered using custom post meta rather than wp_insert_term()? Dec 20, 2012 at 14:17
  • Yes, as you can see I accept any kind of automatic marking posts with the active theme name. The problem with the original question phrasing was how to execute this marking action on post save by writing code in functions.php. Currently I'm one step away from a solution without metadata - see edited post. Dec 20, 2012 at 15:17

1 Answer 1


I would create custom post meta for this data, as it seems the most logical. It should be easy to implement, since you don't need to expose this custom meta data to the UI; just add a callback to save_post.

You can use wp_get_theme() to retrieve information about the current Theme. This function returns an instance of the WP_Theme object.

function wpse76752_add_post_meta() {
    global $post;
    $current_theme = wp_get_theme();
    update_post_meta( $post->ID, '_current_theme', $current_theme->Name );
add_action( 'save_post', 'wpse76752_add_post_meta' );

Note that I prefaced the custom post meta key with an underscore. This prevents the meta key from being listed in the "custom fields" dropdown in the Edit Post screen. (Basically, it makes it an "internal" post meta key, that is hidden from the UI unless you explicitly expose it.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.