There is an answer to this question asked Apr 23, 2020 at 10:32 by Izhar Mehdi and answered answered Apr 23, 2020 at 11:27 by Mathanagopal S.
Answer: Create the default.xml in your module (app/code/VendorName/ModuleName).
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.main">
<container name="page.messages"
htmlTag="div"
htmlClass="page messages"
after="-">
<block class="MagentoFrameworkViewElementTemplate"
name="ajax.message.placeholder"
template="Magento_Theme::html/messages.phtml"/>
<block class="MagentoFrameworkViewElementMessages"
name="messages" as="messages"
template="Magento_Theme::messages.phtml"/>
</container>
</referenceContainer>
</body>
While this answer works, the problem is that this answer seems to make the change to all messages, not just the “add to cart” messages.
When I make the change, this breaks my success message on the “contact us” page. The form works correctly and I get the email, but I no longer get the success message “Thanks for contacting us with your comments and questions. We’ll respond to you very soon.” unless I remove the code.
I’m using Magento 2.4.3-p1