I’m currently working on an appcache plugin for WordPress. One thing that it should do is add a manifest reference in the <html> tag of the site. It has to resemble something like this:

<html manifest="manifest.appcache">

Is there any way of doing this programmatically within a plugin? My current idea would be to identify the <html part of a theme’s header file and inject the manifest using something like str_replace(). However, I can’t see a way of filtering the output of the get_header() function either via the get_header() action or load_template() function.

If anyone has any ideas I’d appreciate help.

1
1

You can probably use the language_attributes filter (from the language_attributes() function) to add it.

It should receive an output like lang="en" and you can add to it before printing to the <html> tag:

add_filter( 'language_attributes', function( $attr )
{
    return "{$attr} manifest=\"manifest.appcache\"";
} );

or without a anonymous function

add_filter( 'language_attributes', 'wpse140730_add_manifest_to_language_attributes' );

function wpse140730_add_manifest_to_language_attributes($output) {

    return $output . ' manifest="manifest.appcache"';

}

Leave a Reply

Your email address will not be published. Required fields are marked *