Adds the ability to override the page meta title and add in meta descriptions and keywords for pages.
This plugin uses custom fields to allow the page title tag to be customised and differ from the actual page title.
Both meta descriptions and keywords can also be added if required.
Page meta details can be modified on any publicly accessible post type, such as posts and pages, as well as custom post types.
Theme and plugin developers should note that it is possible override the page title within your templates by setting $wppm_title = 'Newly defined title';
before the call to get_header();
.
Here we go:
pagemeta
folder to the /wp-content/plugins/
directorySettings > Reading
options.The field names used are _pagemeta_title
, _pagemeta_description
and _pagemeta_keywords
.
The underscore prefix prevents it from being displayed in the list of custom fields.
If a custom title is set for a post type, the plugin will automatically hook into the wp_title
function to modify the output.
This uses the parameters passed via wp_title and will completely override the title.
You can customise the output further using the pagemeta_title
filter, which uses the same parameters plus the original post title value.
In this example we prefix the original title to the custom title.
add_filter( 'pagemeta_title', function( $title, $sep, $seplocation, $original_title ) { return $original_title . $title; }, 10, 4 );
Please refer to the Codex for further information on the add_filter.
This plugin makes use of the wp_head
hook action, therefore in order for it to work there must be a call to wp_head in the current theme header file.
More information on this can be found in the WordPress Codex.
Yes, as of version 1.5 you can modify which fields are used using the pagemeta_fields
filter:
add_filter( 'pagemeta_fields', function( $fields ) { $fields['author'] = 'Author'; // Add a new field. unset( $fields['keywords'] ); // Remove a default field. return $fields; } );
The default fields are ‘title’, ‘description’ and ‘keywords’.
The page meta values can be output within posts using the [postmeta]
shortcode.
Passing through a name
attribute will determine which value is returned, for example to output the description value use the following.
[postmeta name="description"]
Name values are determined by the fields set, by default these are ‘title’, ‘description’ and ‘keywords’.
To output meta values in template files, you can make use of the_pagemeta
function.
<?php if ( function_exists( 'the_pagemeta' ) ) { the_pagemeta( 'description' ); } ?>
This will output the value, in order to return the value or lookup a specific post ID you can use get_the_pagemeta
.
<?php if ( function_exists( 'get_the_pagemeta' ) ) { $description = get_the_pagemeta( 'description' ); } ?> <?php if ( function_exists( 'get_the_pagemeta' ) ) { $description = get_the_pagemeta( 'description', // Page meta value name 123 // Post ID to lookup ); } ?>
Not that these functions will return the raw values prior to any output manipulation.
pagemeta_fields
filter.pagemeta_title
.the_pagemeta
and get_the_pagemeta
functions added.