Remove the ":" colon from the_meta function

  1. matharchod

    I'd like to suggest that the WordPress team consider removing the ":" colon from the_meta function in the "post-template.php" doc. That way, users will be able to decide what comes after the meta-key when they enter the name of the key in the Admin panel. I spent a day and a half trying to find out how to turn "Meta Topic:" to "Meta Topic"!

    Posted: 9 years ago #
  2. notthatugly


    I agree that hardcoded text in function outputs should be avoided if at all possible, but at the same time the_meta shouldn't be confused with a fully-fledged template function such as the_tags or the_category. The argument has always been that custom fields are best handled through specific plugins, so core support is minimal.

    Minor tweaks can easily be handled by copy/pasting the code and using it as a base for an alternative function (the_better_meta ?) in your theme's functions.php. I don't think this tag is widely used enough to make it worth their while to beef it up with parameters.

    Posted: 9 years ago #
  3. Dgold


    It would mess up a lot of existing websites if they remove the colon : now.

    Too many custom themes are already displaying the_meta and counting on the layout to stay the same in future versions of WP.

    However note that you CAN already do the way you want, but you will need to use the template tags for

    So you can format any way you want such as,
    Key - Value
    Key = Value
    Key, Value
    Key (Value)

    or whatever you want.

    The only difficulty there is, you have to go 1 key at a time, and list them all. Instead of 1 template tag that gives you a list of all your custom fields (the_meta).

    Posted: 9 years ago #
  4. There's a filter (the_meta_key) applied to each li in the list. Combine that with a fairly simple regex or even simple string replacement, and you should be fine: You could even completely build the list yourself if you want, since key and value are included in the filter.

    To remove the colon:

    function remove_colons_from_meta( $meta, $key, $value ) {
    	return str_replace( ">$key:</span>", ">$key</span>", $meta );
    add_filter( 'the_meta_key', 'remove_colons_from_meta', null, 3);

    To make your own:

    function custom_meta_list_items( $meta, $key, $value ) {
    	return "<li>Meta Key: $key<br />\r\nMeta value: $value</li>";
    add_filter( 'the_meta_key', 'custom_meta_list_items', null, 3);
    Posted: 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    4 Votes
  • Status

    Sorry, not right now