0

I want to add/edit meta tag keyword and descriptions as per my need.

Currently meta tag "twitter:description" is showing short description but I want to add some other content as per my conditions, so please share my path where I can edit these meta tags.

Also, I want to add meta tag "og:image" and URL will be dynamic.

1 Answer 1

1

you can add/edit meta tags from the controller by doing following.

1) Go to your controller file

namespace Vendor\Frontendsample\Controller\Index;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;

class Index extends Action {

    protected $resultPageFactory;

    public function __construct(
    Context $context, PageFactory $resultPageFactory) {
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }

    /**
     * @return \Magento\Framework\Controller\Result\Forward|\Magento\Framework\View\Result\Page
     */
    public function execute() {
        $resultPage = $this->resultPageFactory->create();
        $resultPage->getConfig()->getTitle()->set("Title");
        $resultPage->getConfig()->setDescription("Description");
        $resultPage->getConfig()->setKeywords("Key Words");

        return $resultPage;
    }
}
1
  • please accept answer if your problem solved
    – Hitesh
    Oct 18, 2018 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.