Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Headspace2 for Custom Post Type Problem WordPress

  • SOLVED

I am using Headspace2 as my SEO on my Wordpress site.

Currently I have a Custom Post Type called "Accommodation" and I have registered the following code so that I can optimise each post in the Custom Post Type.

// Headspace Accommodation.
function accommodation_headpspace_add_custom_box() {
global $headspace2;
if ( function_exists( 'add_meta_box' ) && is_object( $headspace2 ) ) {
add_meta_box( 'headspacestuff', __('HeadSpace', 'headspace'), array( &$headspace2, 'metabox' ), 'accommodation', 'normal', 'high' );
}
}
add_action( 'wp_print_scripts', 'accommodation_headpspace_add_custom_box' );
// Headspace Accommodation END.


It works, however whenever I drag a box up and down, for example dragging the headpsace custom meta box below the Custom Fields box, it duplicates the Headspace2 box, and creates one with 2 sets of numbers blow the text fields. Please see attached picture for an example.

I am after a new bit of code to ensure this duplication doesn't happen.

Answers (2)

2011-04-22

AdamGold answers:

Hi Tom, you need to use another action to display the meta box correctly. Try this one:

// Headspace Accommodation.

function accommodation_headpspace_add_custom_box() {

global $headspace2;

if ( function_exists( 'add_meta_box' ) && is_object( $headspace2 ) ) {

add_meta_box( 'headspacestuff', __('HeadSpace', 'headspace'), array( &$headspace2, 'metabox' ), 'accommodation', 'normal', 'high' );

}

}

add_action( 'admin_init', 'accommodation_headpspace_add_custom_box' );

// Headspace Accommodation END.


parksey18 comments:

Thanks mate, great stuff.

2011-04-22

Hameedullah Khan answers:

You should use add_meta_box in admin_init.


// Headspace Accommodation.

function accommodation_headpspace_add_custom_box() {

global $headspace2;

if ( function_exists( 'add_meta_box' ) && is_object( $headspace2 ) ) {

add_meta_box( 'headspacestuff', __('HeadSpace', 'headspace'), array( &$headspace2, 'metabox' ), 'accommodation', 'normal', 'high' );

}

}

add_action( 'admin_init', 'accommodation_headpspace_add_custom_box' );

// Headspace Accommodation END.


I am not sure what is $headspace2 variable and if it exists during admin_init.