WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Anyone thinks this should not work? I can't make it work for some reason.

add_action( 'wp_head', function() {
    switch_to_blog( $blog_id );
    wp_query( 'p=' . $post_id );

The point is that instead of displaying whatever page I am about to display, I choose content from a different blog instead.

share|improve this question
are $blog_id and $post_id in the scope? and also this code alone wont display the content. – Bainternet Aug 19 '12 at 21:45
$blog_id and $post_id are just placeholders for my example, so yes they are in the scope. This code will not in itself display the content, but further down the line the "Wordpress loop" will do it. Right? (I'm not getting 404, I actually display a page template but there is not content in it, one possible reason for this not working is that it's not getting invoked. But I think the hook is suitably chosen.) – user5028 Aug 19 '12 at 22:10
try get_header as your hook – Bainternet Aug 19 '12 at 22:16
Yup, that works. Thank you. – user5028 Aug 19 '12 at 23:05
up vote 0 down vote accepted

For other people with the same issue who don't read comments the solution was to change the hook from wp_head to get_header

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.