5

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.

3
  • Welcome to WP.SE! As a starter: No, there is no filter. You will have to introduce theme authors to your API. But the really hard thing will be to save your manifest file somewhere. Not everything is 0777 in WP for a reason ;)
    – kaiser
    Commented Jul 30, 2014 at 15:45
  • 1
    Thanks @kaiser, I had anticipated the permissions issue. In that instance I'd have the plugin provide instructions for adding the manifest yourself (in the same way that core tells you about editing your .htaccess file). For the output filtering, sigh. Never mind! Thanks again for your help. :)
    – Jack Lenox
    Commented Jul 30, 2014 at 15:52
  • I'm curious if you ever got your plugin working? Because I tried to test AppCache earlier and either I was doing everything wrong, or PHP doesn't seem to be compatible with it: stackoverflow.com/questions/33327024/…
    – NoBugs
    Commented Nov 15, 2015 at 3:18

1 Answer 1

6

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"';

}
2
  • Genius! I totally didn't think about using the language_attributes filter. Thank you so much.
    – Jack Lenox
    Commented Jul 30, 2014 at 16:06
  • glad to help out!
    – moraleida
    Commented Jul 30, 2014 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.