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've added a "Custom Title" field to the Category editor in order to capture a keyword friendly title that can be used separately from the category name. It works great, but it appears as the last input element of the category screen. Ideally, I would like it to sit under the "Name" field (or at the very top). Is this possible?

Here's the code I'm using to add my custom input field to the category edit screen...

if($pagenow == "edit-tags.php" && $_REQUEST['action'] == "edit") 
add_filter('edit_category_form', 'my_category_fields');

function my_category_fields($tag) {
$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);?>
<table class="form-table">
    <tr class="form-field">
        <th scope="row" valign="top"><label for="categoryTitle">Full Category Title</label></th>
        <td><input name="categoryTitle" id="categoryTitle" type="text" size="40" aria-required="false" value="<?php echo $tag_extra_fields[$tag->term_id]['cat_title']; ?>" />
        <p class="description">The title is optional but will be used in place of the name on the category landing page.</p></td>
    </tr>   
</table>
<?php
}
share|improve this question
    
I know it's not an answer, but I'm curious why you would do this at all? Is it to distinguish a human readable category title from an SEO-optimized version you use in the template? –  internetross Jan 12 '11 at 21:38
    
In essence, yes. The default "Name" field is fine for lists such as when someone pulls over a "Category" widget into a sidebar. However, when you are viewing a category landing page, a fully descriptive title works better. But I wouldn't use this "Title" in lists since the default category "Name" field is more appropriate for that, IMHO. –  Scott B Jan 12 '11 at 22:05
    
I do the same thing for post titles. I use the default post/page title in menus and navigation lists, but when I get ready to echo the post/page title on single.php or page.php, I use a custom field that captures a more descriptive (and SEO friendly) title. –  Scott B Jan 12 '11 at 22:07
add comment

2 Answers

up vote 1 down vote accepted

Hi @Scott B:

WordPress doesn't provide the hooks you want but it you are willing to use PHP's output buffering and preg_replace() you can get it to work without hacking core. Here's an answer that talks about the general technique required:

The hooks you'll want to use are 'category_pre_add_form' for ob_start() and 'category_add_form' for ob_get_clean().

share|improve this answer
    
That's an interesting option Mike. Also should eliminate the flicker problem inherent in the javascript option. Thanks as always! –  Scott B Jan 13 '11 at 13:52
    
Great idea. –  MathSmath Jan 13 '11 at 19:02
    
@Scott B - Yes, I always prefer to do in PHP whenever possible. I like to use jQuery for interactivity, not to bandaid less-than-ideal HTML generation because, as you mention, it's a lot cleaner. –  MikeSchinkel Jan 13 '11 at 23:18
    
@MathSmath - Thanks. I've had a client push me really hard and I've learned there is (almost) always some way to make it work w/o hacking core. Of course it's not always pretty... :) –  MikeSchinkel Jan 13 '11 at 23:18
add comment

There is no php-based solution without hacking core. Crack open the file wp-admin/edt-tag-form.php and you'll see it. The hook you're using is fired right before the submit button, and the rest of the form is hard-coded.

But can probably do this with jQuery. Read my answer to this similar question for an example. The example is for the post edit screen, but the concept should be the same--use jQuery's insertBefore() method to move an element (by ID) before another element (by ID).

share|improve this answer
    
I like your idea with the jQuery bits. But it looks like I'm stuck, since the category edit fields (the TR elements) don't have IDs assigned to them that I can interrogate with jQuery. –  Scott B Jan 13 '11 at 2:36
    
On second thought, since i want to insert my row just after the first row of that table, I suppose I should be able to get another means of DOM traversal than getElementsByID... –  Scott B Jan 13 '11 at 2:39
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.