Skip to content

Best way to customize entry meta fields & data? #9797

Answered by brandonkelly
JoshCoady asked this question in Q&A
Discussion options

You must be logged in to vote

This is a little hacky, and can’t promise that it’s future-proof, but you can remove the Post Date and Expiry Date fields using the craft\base\Element::EVENT_DEFINE_SIDEBAR_HTML event:

use craft\base\Element;
use craft\elements\Entry;
use craft\events\DefineHtmlEvent;
use craft\helpers\Html;
use yii\base\Event;

Event::on(
    Entry::class,
    Element::EVENT_DEFINE_SIDEBAR_HTML,
    function(DefineHtmlEvent $event) {
        $remove = ['postDate', 'expiryDate'];
        foreach ($remove as $id) {
            // Find the beginning of the field container
            $id = preg_quote($id, '/');
            if (preg_match("/<div\b[^\>]*id=\"$id-field\"/", $event->html, $matches, PREG_OFFSET_…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants