• Hi,

    does anyone have the idea on how to replace the wp implementation of the post_title with a custom one? I’m looking for a way to remove the current input and replace it with my own.

    • This topic was modified 4 years, 11 months ago by wpnoob654.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator bcworkz

    (@bcworkz)

    For input, not output? You can remove title support from the global $_wp_post_type_features for any particular post type. If you do that, you’ll need some alternative scheme for setting the post slug.

    You can change the title after it’s submitted for saving through the ‘wp_insert_post_data’ filter.

    Thread Starter wpnoob654

    (@wpnoob654)

    I need it for input but I want to keep all the functionality that comes with the field in the business logic of wp so I wanted to avoid removing post-type features, I just need to insert my own HTML instead of the default one. Btw, thanks for reaching out!

    Moderator bcworkz

    (@bcworkz)

    I suppose some sort of JavaScript could manipulate the field’s content within the editor. But then a user could alter this after the script had run. Unless you add an event listener for the field to disallow further changes.

    A server side solution would involve the ‘wp_insert_post_data’ filter like I said. The title can be set to anything you could code in PHP, regardless of what is entered on the form. Or this could be a way of enforcing whatever you had JavaScript do earlier.

    The best approach depends on what sort of user experience is desired.

    Thread Starter wpnoob654

    (@wpnoob654)

    Ok, thanks. The documentation is not very clear on what gets removed when you remove support for the title when removing it from _wp_post_type_features. As you said there is a dependency on the post_name i.e. slug. I’m worried about other dependencies that depend on the post title, is that documented anywhere?

    Moderator bcworkz

    (@bcworkz)

    No such documentation that I know of. If you still want a title, but wish that it be set by algorithm and not by user, removing support would be the wrong approach. The one I would take is hide the field via CSS, and populate its value with JS. The set value could be enforced server side if you’re concerned about mischievous users bypassing CSS and JS in an attempt to force their own value.

    Thread Starter wpnoob654

    (@wpnoob654)

    Yeah, I agree. Thanks for your input!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Title customization using post_title’ is closed to new replies.