Make WordPress Core

Opened 3 years ago

Closed 14 months 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:


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)

#1 @ev3rywh3re
3 years ago

  • Cc jess@… added

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. ;)


Been so busy for quite a while, so I'm actually surprised this sort of thing hasn't happened yet.

#3 @ryanve
3 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 @ryanve
3 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

#5 @DrewAPicture
14 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This ticket was dependent on #23236 (wontfixed) and there's been no other show of interest in the last 17 months. Closing as wontfix.

Note: See TracTickets for help on using tickets.