Reputation: 578
Is there a way to change the text of the button add child page of default Page model of Wagtail?
Upvotes: 0
Views: 539
Reputation: 1
Minor suggestion to avoid having to re-construct the button, since we are just replacing the text. Should also build this out so that it dynamically changes if the child pages are limited to a single content type.
wagtail_hooks.py
@hooks.register('construct_page_listing_buttons')
def replace_page_listing_button_item(buttons, page, page_perms, is_parent=False, context=None):
for index, button in enumerate(buttons):
# basic code only - recommend you find a more robust way to confirm this is the add child page button
if button.label == 'Add child page':
button.label = 'Add New...'
buttons[index] = button # update the matched button with a new one (note. PageListingButton is used in page listing)
Upvotes: 0
Reputation: 5196
Wagtail provides a hooks system to override functionality throughout the admin interface. One of the hooks available is construct_page_listing_buttons which lets you customise the final list of buttons before it renders.
You will need to create a file in any app called wagtail_hooks.py
which Wagtail will execute at the start. See - https://docs.wagtail.io/en/stable/reference/hooks.html#hooks
In the source you can see the add page button generation for reference on how they are added.
wagtail_hooks.py
from wagtail.core import hooks
from wagtail.admin.widgets import Button, PageListingButton
@hooks.register('construct_page_listing_buttons')
def replace_page_listing_button_item(buttons, page, page_perms, is_parent=False, context=None):
for index, button in enumerate(buttons):
# basic code only - recommend you find a more robust way to confirm this is the add child page button
if button.label == 'Add child page':
new_button = Button(...)
buttons[index] = new_button # update the matched button with a new one (note. PageListingButton is used in page listing)
Upvotes: 1