Opened 12 years ago
Closed 10 years ago
#23237 closed enhancement (wontfix)
Add tag function to format markup
Reported by: | ryanve | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Related to #23236 I'd like to add a generic function for making html tags:
wp_tag( $tagname, $attrs, $inner_html ) // returns an html tag wp_tag_e( $tagname, $attrs, $inner_html ) // echoes an html tag
$attrs could be an array|string, and the tag should only close if $inner_html is defined, like tag() in phat.
Change History (5)
#2
@
12 years ago
I also have such an utility; it's called html()
:
https://github.com/scribu/wp-scb-framework/blob/r57/Util.php#L143-178
Usage: https://github.com/scribu/wp-scb-framework/wiki/html()
#3
@
12 years ago
@ev3rywh3re @scribu Thanks—I'm gonna work on a version that takes the best ideas from all of em. #23236 should handle the attributes argument, and that's the hardest part. I'm on the fence about whether a hook is needed within wp_tag()
.
#4
@
11 years ago
This ticket is dependent on #23236. I added wphat.php in the phat repo called where I'm working on these. The syntax wp_tag($tagname, $attrs, $inner)
described above is ideal IMO. A closing tag is added when $inner
is not null
. Do we need to provide a syntax for auto-closing XHTML self-closing tags? If needed I think one of these syntaxes could work:
wp_tag('img/', $attrs)
reads better
wp_tag('img', $attrs, true)
makes secondary use of the $inner
param
I'm always trying to get a good simple HTML writing function. Never mind the debate about when it's useful since PHP is already this funky parsing sort-of template language. When doing complex HTML structures with bizarre data a simple tag writing function is helpful.
My pocket-knife-style function I've carried around for years helps me fine, but I'd love to see something cool and mindful of the WordPress nature of actions, filters, and brevity. ;)
https://gist.github.com/4573482
Been so busy for quite a while, so I'm actually surprised this sort of thing hasn't happened yet.