Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to create a simple function that adds or edits data in the <html>. Basically, before the server response is sent, I want to find where this piece of html is written at the top level of the page

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

And based on certain criteria, add a new property & value that tag.

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US" myprop1="val1" myprop2="val2">

Is there an action or filter I can hook into, at it's earliest to modify this? Most likely using regex? Side note, I understand how it break validation, but I need this for my purposes.

Update

To answer couple questions:

  • I know I can insert variables inside of html tags with just PHP. The problem is I can't find where in the WP core the actual starting html tag is being generated so I can replace or modify what's being generated.
  • This will be in a plugin, theme independent, where the html tag is unknown, but 99% of the time it will be the standard output from Wordpress
  • I can't use the header.php in a theme, as I would like this to work on whatever theme is installed. Is this specific tag always generated from the theme? Any way to override theme generated tag (if user specifies this) within a plugin?
share|improve this question
    
Hi Nathan this isn't really related to WordPress, you can insert variables inside HTML tags with PHP. –  Wyck Mar 3 '13 at 18:10
    
is the <html> head always going to be the same before your changes? or is this for a plugin where the html tag is unknown? If you know the html is always going to be the same you should be able to use buffer/string replace to do this. –  BandonRandon Mar 3 '13 at 18:14
    
Is there some reason you can't edit the theme's header.php? I don't know why you think you need regex. Maybe you do but a good answer isn't possible without know what you are trying to to (and this is on its way to being closed as off-topic so hopefully the additional information makes the question WordPress specific.) –  s_ha_dum Mar 3 '13 at 18:52
    
Thanks guys, updated question. –  Nathan Mar 3 '13 at 19:47
add comment

1 Answer

up vote 2 down vote accepted

If you can't edit your header.php, or would prefer not to, most decent WordPress themes should have (and certainly any that pass theme review to be in the official repository)

<html <?php language_attributes();?> >

in the opening html tag in the header.php template.

There is a filter in the language_attributes() function that allows plugins/child themes to modify the ouput, like so:

function wpa89133( $output ) {
    $output .= ' myprop1="val1" myprop2="val2"';
    return $output;
}
add_filter( 'language_attributes', 'wpa89133' );
share|improve this answer
    
exactly what I was looking for, thanks! –  Nathan Mar 3 '13 at 21:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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