Project

General

Profile

Plugin Functionality Customization

Add-Meta-Tags, apart from the settings that are available in the plugin settings page at Settings->Metadata of the WordPress administration interface, also contains some filter hooks that can be used in order to programmatically modify its functionality.

Read more about:

Limit generated metadata to specific post types

You want to limit the generation of metadata by Add-Meta-Tags to specific post types.

This can easily be done by hooking a custom function to the amt_supported_post_types filter:

function limit_metadata_to_post_types( $post_types ) {
    // ... process and return the $post_types array
    // ... or just return a custom array of post types
    return array( 'post', 'book', 'project');
}
add_filter( 'amt_supported_post_types', 'limit_metadata_to_post_types', 10, 1 );

Modify the accepted elements of 'Full Mat Tags' box

Add the title element to the valid html elements for use in the full meta tags box.

This can easily be done by hooking custom functions to the amt_valid_full_metatag_html filter:

function extend_full_metatag_valid_elements( $valid_elements ) {
    // Construct the title element array (key: element name, value: array of valid attributes)
    $title_element = array( 'title' => array() );
    // Append the 'title' element to the valid elements
    $valid_elements = array_merge( $valid_elements, $title_element );
    return $valid_elements;
}
add_filter( 'amt_valid_full_metatag_html', 'extend_full_metatag_valid_elements', 10, 1 );

Custom Default Image Sizes

Customize the default image sizes used when generating image related meta tags for front/archive, content and attachment pages.

This can easily be done by hooking custom functions to the amt_image_size_index, amt_image_size_content, amt_image_size_attachment filters:

Here we customize the generation of all image related meta tag, so that the full image size is used. Since the same image size is used for all types of pages, a single function is hooked to all filters.

function amt_use_full_image_size_in_all_meta_tags( $size ) {
    return 'full';
}
add_filter( 'amt_image_size_index', 'amt_use_full_image_size_in_all_meta_tags', 10, 1 );
add_filter( 'amt_image_size_content', 'amt_use_full_image_size_in_all_meta_tags', 10, 1 );
add_filter( 'amt_image_size_attachment', 'amt_use_full_image_size_in_all_meta_tags', 10, 1 );
add_filter( 'amt_image_size_product', 'amt_use_full_image_size_in_all_meta_tags', 10, 1 );

Compact Image Meta Tags

Generate compact image meta tags (meta tags for width/height/type are suppressed).

This can easily be done by hooking a custom function to the amt_extended_image_tags filter:

add_filter( 'amt_extended_image_tags', '__return_false' );

Custom Generic Descriptions on Archives

Customize the generic descriptions in the category, tag, custom taxonomy, author and custom post type archives.

This can easily be done by hooking custom functions to the amt_generic_description_category_archive, amt_generic_description_tag_archive, amt_generic_description_TAXONOMYSLUG_archive, amt_generic_description_author_archive and amt_generic_description_posttype_POSTTYPESLUG_archive filters:

function amt_custom_category_archive_description( $default ) {
    return 'Articles in the %s section.';
}
add_filter( 'amt_generic_description_category_archive', 'amt_custom_category_archive_description', 10, 1 );

function amt_custom_tag_archive_description( $default ) {
    return 'Products tagged with %s.';
}
add_filter( 'amt_generic_description_tag_archive', 'amt_custom_tag_archive_description', 10, 1 );

function amt_custom_TAXONOMYSLUG_archive_description( $default ) {
    return 'Members of the %s group.';
}
add_filter( 'amt_generic_description_TAXONOMYSLUG_archive', 'amt_custom_TAXONOMYSLUG_archive_description', 10, 1 );

function amt_custom_author_archive_description( $default ) {
    return 'Projects started by %s.';
}
add_filter( 'amt_generic_description_author_archive', 'amt_custom_author_archive_description', 10, 1 );

function amt_custom_posttype_POSTTYPESLUG_archive_description( $default ) {
    return '%s archive.';
}
add_filter( 'amt_generic_description_posttype_POSTTYPESLUG_archive', 'amt_custom_posttype_POSTTYPESLUG_archive_description', 10, 1 );

Custom Permissions for the Metadata metabox

You want to set stricter permissions for the Metadata metabox.

This can easily be done by hooking a custom function to the amt_metadata_metabox_permissions filter.

function amt_custom_metadata_metabox_permissions( $default_permissions ) {

    //
    // This array contains the default Metadata metabox permission settings.
    // Regardless of these settings the 'edit_posts' capability is _always_
    // checked when reading/writing metabox data, so the 'edit_posts' capability
    // should be considered as the least restrictive capability that can be used.
    // The available Capabilities vs Roles table can be found here:
    //     http://codex.wordpress.org/Roles_and_Capabilities
    // To disable a box, simply add a very restrictive capability like 'create_users'.
    //
    $permissions = array(
        // Minimum capability for the metabox to appear in the editing
        // screen of the supported post types.
        'global_metabox_capability' => 'edit_posts',
        // The following permissions have an effect only if they are stricter
        // than the permission of the 'global_metabox_capability' setting.
        // Edit these, only if you want to further restrict access to
        // specific boxes, for example the 'full metatags' box.
        'description_box_capability' => 'edit_posts',
        'keywords_box_capability' => 'edit_posts',
        'title_box_capability' => 'edit_posts',
        'news_keywords_box_capability' => 'edit_posts',
        'full_metatags_box_capability' => 'edit_posts',
        'image_url_box_capability' => 'edit_posts',
        'content_locale_box_capability' => 'edit_posts',
        'express_review_box_capability' => 'edit_posts',
        'referenced_list_box_capability' => 'edit_posts'
    );

    return $permissions;
}
add_filter( 'amt_metadata_metabox_permissions', 'amt_custom_metadata_metabox_permissions', 10, 1 );

Twitter Cards Player Size

Customize the size of the video player in Player Twitter Cards.

This can easily be done by hooking a custom function to the amt_twitter_cards_video_player_size filter.

function amt_custom_twitter_cards_video_player_size( $default ) {
    return array(320, 240);
}
add_filter( 'amt_twitter_cards_video_player_size', 'amt_custom_twitter_cards_video_player_size', 10, 1 );

External Images for Categories

Add-Meta-Tags has internal support for assigning a custom image to a taxonomy term. After enabling this feature in the plugin settings, it is possible to set an image in the term editing screen.

However, it is also possible to make the metadata generators use category images added by external plugins.

This can easily be done by hooking a custom function to the amt_taxonomy_force_image_url filter. In the following example, category images, which have been added by the Categories Images plugin, are used.

function use_taxonomy_images_by_categories_images() {
    if ( is_category() && function_exists('z_taxonomy_image_url') ) {
        return z_taxonomy_image_url();
    }
}
add_filter( 'amt_taxonomy_force_image_url', 'use_taxonomy_images_by_categories_images', 100, 2 );

If the Taxonomy Images plugin is used, this can be done with:

function use_taxonomy_images_by_taxonomy_images_plugin( $default, $term ) {
    if ( is_category() || is_tag() || is_tax() ) {
        // Return the image ID
        return apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
        // Alternatively, return the image URL with or without dimensions notation
        //return apply_filters( 'taxonomy-images-queried-term-image-url', '' );
    }
}
add_filter( 'amt_taxonomy_force_image_url', 'use_taxonomy_images_by_taxonomy_images_plugin', 100, 2 );

Alternatively, the amt_taxonomy_image_url_TAXONOMYSLUG_TERMSLUG filter hook can be used, which gets its name dynamically from the taxonomy and the term slugs. For example, the following code returns the image URL when the archive of the term with slug techsupport, which belongs to the taxonomy with slug services, is displayed:

function custom_image_url_services_techsupport( $default ) {
    return 'http://images.example.org/path/to/services_techsupport.jpg';
}
add_filter( 'amt_taxonomy_image_url_services_techsupport', 'custom_image_url_services_techsupport' );

Create Pre-Defined Full Meta Tag Sets

Add-Meta-Tags lets you add full meta tags on a per post basis. It is possible to create pre-defined sets of the meta tags you use more often. Once set up, the meta tag sets are available through a drop down menu above the Full Meta-Tags text area in the post editing screen.

The following sample code adds two groups of meta tags, Citation and Other Set

function amt_set_full_meta_tag_sets( $meta_tag_sets ) {

    // Citation Group
    $meta_tag_sets['Citation'] = array(
        '<meta name="author_email" content="" />',
        '<meta name="citation_volume" content="" />',
        '<meta name="citation_issue" content="" />',
        '<meta name="citation_firstpage" content="" />',
        '<meta name="citation_lastpage" content="" />',
        '<meta name="citation_keywords" content="" />',
        '<meta name="citation_fulltext_html_url" content="" />',
        '<meta name="citation_pdf_url" content="" />',
        '<meta name="citation_doi" content="" />',
    );

    // Other group
    $meta_tag_sets['Other Set'] = array(
        '<meta_name="author_email" content=""/>',
        '<meta name="citation_pdf_url" content=""/>',
    );

    return $meta_tag_sets;
}
add_filter( 'amt_full_meta_tag_sets', 'amt_set_full_meta_tag_sets' );

Stop automatic generation of schema.org metadata on the front page

Sometimes the schema.org metadata of the front page might be hard coded into the theme or provided by a third party plugin, which has been specifically designed for your organization. In such cases, Add-Meta-Tags is no longer needed to automatically generate this metadata. The following code snippet instructs Add-Meta-Tags to stop generating schema.org metadata on the front page.

function amt_schemaorg_skip_front_page( $default ) {
    if ( is_front_page() || is_home() ) {
        return array();
    }
    return $default;
}
add_filter( 'amt_schemaorg_metadata_footer', 'amt_schemaorg_skip_front_page' );
add_filter( 'amt_jsonld_schemaorg_metadata_head', 'amt_schemaorg_skip_front_page' );

Map opening and closing of the Metadata Review Mode panel to the Esc key

Currently, the Esc key can only be used to close the Metadata Review Mode. The following snippet can be used to also open the metadata review by pressing the Esc button.

add_filter('amt_metadata_review_mode_enable_enhanced_script', '__return_true');

Stop the plugin from auto-generating descriptions and keywords meta tags

Preventing the plugin from automatically generating a description and keywords in case a custom description or a keywords list has not been set manually is possible with the following filter based switches:

add_filter( 'amt_generate_description_if_no_manual_data', '__return_false' );
add_filter( 'amt_generate_keywords_if_no_manual_data', '__return_false' );

Please note that stopping the automatic generation of descriptions affects all the metadata generators and could result in having incomplete metadata in your pages. Using the above filter based switches is not recommended, it has not been tested and also no support is provided in case you run into problems with metadata validation.

Customize the main Schema.org entity

The following example shows how to customize the main Schema.org entity of the page.

function amt_set_custom_schemaorg_entity( $default ) {
    if ( is_page('about') ) {
        return 'AboutPage';
    } elseif ( is_page('contact') ) {
        return 'ContactPage';
    } elseif ( is_singular('news_post_type') ) {
        return 'NewsArticle';
    } elseif ( is_singular('blog_post_type') ) {
        return 'BlogPosting';
    } elseif ( is_page() ) {
        return 'WebPage';
    }
    return $default;    // Article
}
add_filter( 'amt_schemaorg_object_main', 'amt_set_custom_schemaorg_entity' );

Prevent the AMP plugin from generating JSON+LD Schema.org metadata

If you have enabled the Schema.org Microdata/JSON+LD generators in the Add-Meta-Tags settings, it is sometimes useful to prevent the AMP plugin from generating its own Schema.org metadata. Add-Meta-Tags never takes any decision to deactivate any functionality of third party plugins, so you have to do it manually with the following snippet:

function amp_prevent_schemaorg_metadata( $metadata, $post ) {
    return array();
}
add_filter( 'amp_post_template_metadata', 'amp_prevent_schemaorg_metadata', 10, 2 );