WordPress.org

Ready to get started?Download WordPress

Forums

Meta SEO Pack
Add meta box to custom post types (6 posts)

  1. Vytas M.
    Member
    Posted 2 years ago #

    If some body uses custom post types and wants to get Meta SEO Pack to work with those types I have made small hack. This hack adds meta box for all post types that have capability_type value set to 'post' or 'page' including built in and all custom post types that have user created.

    Meta SEO pack version: 2.2.1 (Last Updated: 2010-3-17)

    • Open file "meta-seo-pack/meta-seo-pack.php" (you can also use plugin editor inside WordPress).
    • Goto line 211 or near that, and find lines:
      add_meta_box( 'msp_sectionid', 'Meta SEO Pack', array( &$this, 'post_metabox' ), 'post', 'normal', 'high' );
      add_meta_box( 'msp_sectionid', 'Meta SEO Pack', array( &$this, 'post_metabox' ), 'page', 'normal', 'high' );
    • Comment those lines using // or delete them
    • After these lines insert new code:
      // This will also support all custom post types not only built in
      $capability_types=array('page','post');
      foreach ($capability_types as $capability_type ) {
      	$post_types=get_post_types(array('capability_type'=>$capability_type),'names');
      	foreach ($post_types as $post_type ) {
      		add_meta_box( 'msp_sectionid', 'Meta SEO Pack', array( &$this, 'post_metabox' ), $post_type, 'normal', 'high' );
      	}
      }

    This code works for me, hope somebody will find this useful to.

    http://wordpress.org/extend/plugins/meta-seo-pack/

  2. Adam
    Member
    Posted 1 year ago #

    What if Meta SEO Pack is updated? (I know it hasn't been in over 2 years). Could this be placed in the functions.php file of a theme and still work?

    Noticed one thing. I use the Advanced Custom Fields (ACF) plugin. After enabling Meta SEO Pack for custom post types (with your code), the custom fields created by ACF appear, but the content is missing. Any thoughts?

    ACF Plugin Link:
    http://wordpress.org/extend/plugins/advanced-custom-fields/

  3. Vytas M.
    Member
    Posted 1 year ago #

    If it will be updated some day maybe it will include this fix to have possibility add information to all post types.

    About the ACF plugin I do not use it so do not know what to tel. Have you tried to disable my code and checked if ACF works? Check not only on your custom posts but also on normal posts and pages. Does it work or not? By the way what WP version do you use?

  4. Adam
    Member
    Posted 1 year ago #

    I'm using WP 3.4.1

    If I remove your code from the Meta SEO plugin, the custom fields display their content.

    Another strange occurrence: the content of a custom field shows on a regular page, until I drag the Meta SEO content area below the custom field content area to reorder the content boxes (native WP drag-and-drop interface). If I refresh the page (after the re-order), the content appears. If I Update the page or leave the edit page, then come back, the custom fields and Meta SEO Plugin fields show up.

    I Updated and refreshed both a regular page and a custom post type page, and it appears that the Meta SEO Plugin is now working.

    Scared me for a minute when the content disappeared! :)

    I like your addition very much! Is there a way to add your code to a functions.php file? Thanks!

  5. Vytas M.
    Member
    Posted 1 year ago #

    Good to hear that somebody has found this patch useful. About disappearing text I do not know very much because I didn't created this plugin. That peace of code that I have added just lists all post types that are identified as post or page. When you are creating custom post type you set how this post type treats. When you register new post type you set capability_type like http://codex.wordpress.org/Function_Reference/register_post_type That code just finds all custom posts that have capability_type set to 'page' or 'post' and adds Meta SEO Plugin to it. So it was quite interesting that custom field content disappeared to you.

    About adding it to functions.php I can will try later to check one idea that i have just in my head. maybe it will work. If it will be successful I will post solution here.

  6. Adam
    Member
    Posted 1 year ago #

    The custom field content did show up, but only after I refreshed the page or revisited it.

    Maybe there's some kind of refresh that the Meta SEO Pack should do when content blocks are re-arranged on a page or post?

    Your addition does work (only with minor bugs that may not be directly related), so thank you! I look forward to being able to add this to the functions.php file. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic