Project

General

Profile

Migrating to Add-Meta-Tags

Notice

Before you proceed with reading this page, please check this comment of mine on Github regarding all the available options, including using an external plugin to transfer the data.

Introduction

Migrating to Add-Meta-Tags from any other plugin is extremely easy. In fact, if the 3rd party plugin stores data in Custom Fields provided by WordPress, no migration process needs to be done. Add-Meta-Tags can read data from multiple external fields by adding a small snippet of PHP code in the functions.php file of your theme.

This section contains information and code samples that can assist you when migrating to Add-Meta-Tags (AMT).

Although in most cases these snippets do not affect the database in any way, it is always a good idea to backup your data before performing or testing any kind of migration.

Read more about:

Tech Notes

Add-Meta-Tags can read data from external fields in addition to its own fields.

Keep in mind that:

  1. The AMT internal fields have priority over the external fields. If both the internal field and an external field contain data, then the data of the internal field is used.
  2. AMT uses the external fields as read-only sources of data. It never writes to external fields. Whenever the content is saved, every piece of information, which may have been read from an external field, is stored to the relevant AMT internal field. Consequently, when the content is saved, information from external fields is migrated to the AMT internal fields, and external fields have no effect on this specific content any more.

Here is a list of the available external data related filter hooks that can be used to read data from external sources.

Reading data from external fields (Basic example)

Suppose that you use plugin X that saves the descriptions, keywords, and custom title in its own custom fields with the following field names:

  • _x_description
  • _x_keyword
  • _x_title

You want to migrate to Add-Meta-Tags and need to read the data from the old plugin's custom fields.

This can easily be done by hooking custom functions to the amt_external_description_fields, amt_external_keywords_fields and amt_external_title_fields filters:

function read_plugin_x_description_field( $extfields, $post_id ) {
    array_unshift( $extfields, '_x_description' );
    return $extfields;
}
add_filter( 'amt_external_description_fields', 'read_plugin_x_description_field', 10, 2 );

function read_plugin_x_keywords_field( $extfields, $post_id ) {
    array_unshift( $extfields, '_x_keywords' );
    return $extfields;
}
add_filter( 'amt_external_keywords_fields', 'read_plugin_x_keywords_field', 10, 2 );

function read_plugin_x_title_field( $extfields, $post_id ) {
    array_unshift( $extfields, '_x_title' );
    return $extfields;
}
add_filter( 'amt_external_title_fields', 'read_plugin_x_title_field', 10, 2 );

Read data from external fields (Complex example)

Suppose that you have stored SEO data using plugin X and plugin Y. You want Add-Meta-Tags to to try to find data in both of those plugins, but only when generating metadata for pages and posts with any of the following IDs: 1, 2, 5, 8.

This can easily be done by hooking custom functions to the amt_external_description_fields, amt_external_keywords_fields and amt_external_title_fields filters:

function read_plugin_x_description_field( $extfields, $post_id ) {
    if ( is_page() || in_array( $post_id, array( 1, 2, 5, 8 ) ) ) {
        array_unshift( $extfields, '_x_description', '_y_description' );
    }
    return $extfields;
}
add_filter( 'amt_external_description_fields', 'read_plugin_x_description_field', 10, 2 );

function read_plugin_x_keywords_field( $extfields, $post_id ) {
    if ( is_page() || in_array( $post_id, array( 1, 2, 5, 8 ) ) ) {
        array_unshift( $extfields, '_x_keywords', '_y_keywords' );
    }
    return $extfields;
}
add_filter( 'amt_external_keywords_fields', 'read_plugin_x_keywords_field', 10, 2 );

function read_plugin_x_title_field( $extfields, $post_id ) {
    if ( is_page() || in_array( $post_id, array( 1, 2, 5, 8 ) ) ) {
        array_unshift( $extfields, '_x_title', '_y_title' );
    }
    return $extfields;
}
add_filter( 'amt_external_title_fields', 'read_plugin_x_title_field', 10, 2 );