Leftfield Posted May 1 Share Posted May 1 (edited) I created this as a hook and it's working great, so I decided to turn it into a module to share. We have option in the backend to calculate number of characters but this script is calculating the width of the text as it should be displayed in Google's SERP for the meta title and meta description. However, it's not working for some reason (that I can't identify). This (primitive) module should load on the (any) page edit in the backend. As you can see, it's supposed to load two files. I'm not sure why it's not functioning. // Module: SeoTextWidth.module class SeoTextWidth extends WireData implements Module { public static function getModuleInfo() { return [ 'title' => 'SEO field Text Width module', 'summary' => 'This module is calculating width of text in the fields named seo and desc.', 'version' => 1 ]; } public function __construct() { parent::__construct(); } public function init() { $this->addHookAfter('ProcessPageEdit::render', [$this, 'addResources']); } public function addResources(HookArgs $args) { $output = $args->getOutput(); $page = $args->wire('page'); // Check if we're on the page edit view for a valid page if ($page && $page->editable()) { $jsUrl = $this->config->urls->scripts . 'SeoTextWidth.js'; $output->append("<script src='$jsUrl'></script>"); $cssUrl = $this->config->urls->styles . 'SeoTextWidth.css'; $output->prepend("<link rel='stylesheet' href='$cssUrl' />"); } return $output; } } Edited May 1 by Leftfield I am sorry. Mods, please move this post in the Module/Plugin Development Link to comment Share on other sites More sharing options...
Leftfield Posted May 1 Author Share Posted May 1 Resolved. public function init() { $this->addHookAfter('ProcessPageEdit::buildForm', $this, 'addResources'); } public function addResources(HookEvent $event) { $page = $event->object; $this->config->styles->add($this->config->urls->SeoTextWidth . "SeoTextWidth.css"); $this->config->scripts->add($this->config->urls->SeoTextWidth . "SeoTextWidth.js"); } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now