Character limits on Meta title and descriptions boxes
Posted: Sun Oct 27, 2024 2:39 pm
Phoenix 1.0.9.1 PHP 8.0
I have been working on SEO on our website and thought that it may be good to add in the recommended maximum characters and show the character count next to the meta tag boxes. We have first altered the code in the admin/includes/actions/manufactures/infoboxes/edit.php file.
Firstly this is the correct page as it seems to work. Is there a way to override this file?
Secondly can someone confirm that what we are doing is the right approach. Here is the code for the file for my version.
Lack of confidence with coding so just wanting to check that it is right before moving on to the other areas where this could be helpful.
Cheers
I have been working on SEO on our website and thought that it may be good to add in the recommended maximum characters and show the character count next to the meta tag boxes. We have first altered the code in the admin/includes/actions/manufactures/infoboxes/edit.php file.
Firstly this is the correct page as it seems to work. Is there a way to override this file?
Secondly can someone confirm that what we are doing is the right approach. Here is the code for the file for my version.
Code: Select all
$mInfo = &$table_definition['info'];
$heading = TEXT_HEADING_EDIT_MANUFACTURER . ' <small>' . TEXT_EDIT_INTRO . '</small>';
$link = $GLOBALS['link']->set_parameter('mID', (int)$mInfo->manufacturers_id);
$contents = ['form' => new Form('manufacturers', (clone $link)->set_parameter('action', 'save'), 'post', ['enctype' => 'multipart/form-data'])];
$contents[] = ['text' => TEXT_EDIT_INTRO];
$contents[] = ['text' => TEXT_MANUFACTURERS_NAME . '<br>' . new Input('manufacturers_name', ['value' => $mInfo->manufacturers_name])];
$contents[] = ['text' => TEXT_MANUFACTURERS_IMAGE . '<br><div class="custom-file mb-2">' . new Input('manufacturers_image', ['id' => 'inputManufacturersImage', 'class' => 'custom-file-input'], 'file') . '<label class="custom-file-label" for="inputManufacturersImage">' . $mInfo->manufacturers_image . '</label></div>'];
$manufacturer_inputs_string = $manufacturer_description_string = $manufacturer_seo_description_string = $manufacturer_seo_title_string = '';
foreach (language::load_all() as $l) {
$manufacturer = $GLOBALS['db']->query(sprintf(<<<'EOSQL'
SELECT manufacturers_url, manufacturers_seo_title, manufacturers_description, manufacturers_seo_description
FROM manufacturers_info
WHERE manufacturers_id = %d AND languages_id = %d
EOSQL
, (int)$mInfo->manufacturers_id, (int)$l['id']))->fetch_assoc();
$flag_image = $GLOBALS['Admin']->catalog_image("includes/languages/{$l['directory']}/images/{$l['image']}", [], $l['name']);
// URL input without character count
$manufacturer_inputs_string .= '<div class="input-group"><div class="input-group-prepend"><span class="input-group-text">' . $flag_image . '</span></div>' . new Input("manufacturers_url[{$l['id']}]", ['value' => $manufacturer['manufacturers_url']]) . '</div>';
// SEO Title input with character count below
// SEO Title input with character count below, using a textarea for two rows
$seo_title_char_count = strlen($manufacturer['manufacturers_seo_title'] ?? '');
$manufacturer_seo_title_string .= '<div class="input-group"><div class="input-group-prepend"><span class="input-group-text">' . $flag_image . '</span></div>'
. (new Textarea("manufacturers_seo_title[{$l['id']}]", ['cols' => '80', 'rows' => '2', 'oninput' => "updateCharCount(this, 60, 'manufacturers_seo_title_count_{$l['id']}')"]))
->set_text($manufacturer['manufacturers_seo_title'])
. '</div><span id="manufacturers_seo_title_count_' . $l['id'] . '" class="char-count" style="float: right;">' . $seo_title_char_count . '/60</span>';
// Description textarea without character count
$manufacturer_description_string .= '<div class="input-group"><div class="input-group-prepend"><span class="input-group-text">' . $flag_image->set('style', 'vertical-align: top;') . '</span></div>'
. (new Textarea("manufacturers_description[{$l['id']}]", ['cols' => '80', 'rows' => '10']))->set_text($manufacturer['manufacturers_description']) . '</div>';
// SEO Description textarea with character count below
$seo_description_char_count = strlen($manufacturer['manufacturers_seo_description'] ?? '');
$manufacturer_seo_description_string .= '<div class="input-group"><div class="input-group-prepend"><span class="input-group-text">' . $flag_image . '</span></div>'
. (new Textarea("manufacturers_seo_description[{$l['id']}]", ['cols' => '80', 'rows' => '5', 'oninput' => "updateCharCount(this, 160, 'manufacturers_seo_description_count_{$l['id']}')"]))->set_text($manufacturer['manufacturers_seo_description'])
. '</div><span id="manufacturers_seo_description_count_' . $l['id'] . '" class="char-count" style="float: right;">' . $seo_description_char_count . '/160</span>';
}
$contents[] = ['text' => TEXT_MANUFACTURERS_URL . $manufacturer_inputs_string];
$contents[] = ['text' => TEXT_EDIT_MANUFACTURERS_SEO_TITLE . $manufacturer_seo_title_string];
$contents[] = ['text' => TEXT_EDIT_MANUFACTURERS_DESCRIPTION . $manufacturer_description_string];
$contents[] = ['text' => TEXT_EDIT_MANUFACTURERS_SEO_DESCRIPTION . $manufacturer_seo_description_string];
$contents[] = [
'class' => 'text-center',
'text' => new Button(IMAGE_SAVE, 'fas fa-save', 'btn-success mr-2')
. $GLOBALS['Admin']->button(IMAGE_CANCEL, 'fas fa-times', 'btn-light', $link),
];
Cheers