Updated folder

This commit is contained in:
Andreas Andersen 2026-04-16 18:52:37 +02:00
parent 239ebc4964
commit e1f4ba78c4
4 changed files with 1674 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,125 @@
.ansico-wp-basic-metabox .description {
display: block;
margin-top: 4px;
}
.ansico-wp-basic-counter {
display: block;
margin-top: 6px;
font-size: 12px;
font-weight: 600;
}
.ansico-wp-basic-counter.is-good {
color: #2f6f3e;
}
.ansico-wp-basic-counter.is-warning {
color: #b45309;
}
.ansico-wp-basic-counter.is-danger {
color: #b32d2e;
}
.ansico-wp-basic-snippet-wrapper {
margin-top: 18px;
border-top: 1px solid #e0e0e0;
padding-top: 14px;
}
.ansico-wp-basic-snippet {
margin-top: 12px;
background: #fff;
padding: 6px 0;
max-width: 652px;
font-family: Arial, sans-serif;
}
.ansico-wp-basic-snippet-site {
color: #202124;
font-size: 14px;
line-height: 1.3;
margin-bottom: 1px;
}
.ansico-wp-basic-snippet-url {
color: #4d5156;
font-size: 14px;
line-height: 1.3;
margin-bottom: 3px;
word-break: break-word;
}
.ansico-wp-basic-snippet-title {
color: #1a0dab;
font-size: 22px;
line-height: 1.3;
margin-bottom: 4px;
cursor: default;
}
.ansico-wp-basic-snippet-description {
color: #4d5156;
font-size: 14px;
line-height: 1.58;
}
.ansico-wp-basic-truncation-note {
margin-top: 8px;
}
.ansico-wp-basic-truncation-note.is-warning {
color: #b45309;
font-weight: 600;
}
.ansico-wp-basic-settings-page .form-table th {
width: 280px;
}
.ansico-wp-basic-settings-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 16px;
}
.ansico-wp-basic-settings-card {
background: #fff;
border: 1px solid #dcdcde;
border-radius: 8px;
padding: 14px;
}
.ansico-wp-basic-settings-card h3 {
margin-top: 0;
}
.ansico-wp-basic-term-fields .ansico-wp-basic-metabox,
.ansico-wp-basic-term-fields-wrap .ansico-wp-basic-metabox {
background: #fff;
}
.ansico-wp-basic-tools-box p {
margin: 0 0 14px;
}
.ansico-wp-basic-tools-box label strong {
display: inline-block;
margin-bottom: 6px;
}
#ansico_wp_basic_change_post_type,
.ansico-post-type-select {
width: auto;
min-width: 0;
max-width: 220px;
display: inline-block;
vertical-align: middle;
}
.ansico-wp-basic-tools-box .description {
display: block;
margin-top: 6px;
}

View file

@ -0,0 +1,160 @@
document.addEventListener('DOMContentLoaded', function () {
var titleInput = document.getElementById('ansico_wp_basic_meta_title');
var descInput = document.getElementById('ansico_wp_basic_meta_description');
var snippet = document.querySelector('.ansico-wp-basic-snippet');
if (!titleInput || !descInput || !snippet) {
return;
}
var titleTarget = snippet.querySelector('.ansico-wp-basic-snippet-title');
var descTextTarget = snippet.querySelector('.ansico-wp-basic-snippet-description-text');
var urlTarget = snippet.querySelector('.ansico-wp-basic-snippet-url');
var truncationNote = document.querySelector('.ansico-wp-basic-truncation-note');
var titleCounter = document.querySelector('[data-counter-for="title"]');
var descCounter = document.querySelector('[data-counter-for="description"]');
var titleMaxPixels = 580;
var descMaxPixels = 920;
var titleIdealMin = 30;
var titleIdealMax = 60;
var descIdealMin = 70;
var descIdealMax = 155;
var titleCanvas = document.createElement('canvas');
var descCanvas = document.createElement('canvas');
var titleContext = titleCanvas.getContext('2d');
var descContext = descCanvas.getContext('2d');
titleContext.font = '400 22px Arial';
descContext.font = '400 14px Arial';
function measure(context, text) {
return Math.round(context.measureText(text || '').width);
}
function truncateByPixels(text, maxPixels, context) {
text = (text || '').trim();
var fullWidth = measure(context, text);
if (!text || fullWidth <= maxPixels) {
return {
visible: text,
isTruncated: false,
hiddenChars: 0,
hiddenText: '',
width: fullWidth
};
}
var ellipsis = '…';
var low = 0;
var high = text.length;
var best = '';
while (low <= high) {
var mid = Math.floor((low + high) / 2);
var candidate = text.slice(0, mid).replace(/[\s.,;:-]+$/u, '');
var candidateWithEllipsis = candidate + ellipsis;
if (measure(context, candidateWithEllipsis) <= maxPixels) {
best = candidate;
low = mid + 1;
} else {
high = mid - 1;
}
}
if (!best) {
best = text.slice(0, 1);
}
var hiddenText = text.slice(best.length).trim();
return {
visible: best + ellipsis,
isTruncated: true,
hiddenChars: hiddenText.length,
hiddenText: hiddenText,
width: fullWidth
};
}
function setCounter(el, current, minIdeal, maxIdeal, pxWidth, pxLimit, overflowText) {
if (!el) {
return;
}
el.classList.remove('is-good', 'is-warning', 'is-danger');
var statusClass = 'is-good';
var notes = [];
if (current === 0) {
statusClass = 'is-warning';
notes.push('empty');
} else if (current < minIdeal) {
statusClass = 'is-warning';
notes.push('a bit short');
}
if (current > maxIdeal || pxWidth > pxLimit) {
statusClass = (current > maxIdeal + 15 || pxWidth > pxLimit + 120) ? 'is-danger' : 'is-warning';
notes.push(overflowText);
}
el.classList.add(statusClass);
el.textContent = current + ' chars · ' + pxWidth + ' px';
if (notes.length) {
el.textContent += ' — ' + notes.join(' · ');
}
}
function updateSnippet() {
var rawTitle = titleInput.value.trim() || snippet.dataset.fallbackTitle || '';
var siteName = (snippet.dataset.siteName || '').trim();
var title = rawTitle;
if (siteName && rawTitle.toLowerCase().indexOf(siteName.toLowerCase()) === -1) {
title += ' - ' + siteName;
}
var desc = descInput.value.trim() || 'This is how your page may appear in Google search results when a meta description is available.';
var permalink;
try {
permalink = new URL(snippet.dataset.permalink);
} catch (e) {
permalink = null;
}
var host = permalink ? permalink.hostname.replace(/^www\./, '') : '';
var path = permalink ? permalink.pathname.replace(/^\//, '').replace(/\/$/, '') : '';
var prettyUrl = host;
if (path) {
prettyUrl += ' ' + path.replace(/\//g, ' ');
}
var titleResult = truncateByPixels(title, titleMaxPixels, titleContext);
var descResult = truncateByPixels(desc, descMaxPixels, descContext);
var rawTitleWidth = measure(titleContext, title);
var rawDescWidth = measure(descContext, desc);
titleTarget.textContent = titleResult.visible;
descTextTarget.textContent = descResult.visible;
urlTarget.textContent = prettyUrl;
setCounter(titleCounter, rawTitle.length, titleIdealMin, titleIdealMax, rawTitleWidth, titleMaxPixels, 'will truncate in preview');
setCounter(descCounter, desc.length, descIdealMin, descIdealMax, rawDescWidth, descMaxPixels, 'will truncate in preview');
if (truncationNote) {
if (descResult.isTruncated) {
truncationNote.textContent = 'Preview is truncating the meta description. About ' + descResult.hiddenChars + ' characters are no longer visible.';
truncationNote.classList.add('is-warning');
} else {
truncationNote.textContent = 'Preview currently fits within the available description space.';
truncationNote.classList.remove('is-warning');
}
}
}
titleInput.addEventListener('input', updateSnippet);
descInput.addEventListener('input', updateSnippet);
updateSnippet();
});

View file

@ -0,0 +1,43 @@
=== Ansico WP Basic ===
Contributors: ansico
Tags: seo, meta title, meta description, search preview
Requires at least: 6.0
Tested up to: 6.5
Requires PHP: 7.4
Stable tag: 0.0.0.2
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Basic SEO fields for posts, pages, custom post types, author archives, taxonomy archives, and special archive pages.
== Description ==
Ansico WP Basic adds simple SEO fields to WordPress:
- Meta title and meta description fields for posts, pages, and public custom post types
- Live search result preview in the editor
- SEO fields for author archives via user profiles
- SEO fields for taxonomy archives such as categories, tags, and public custom taxonomies
- Settings for archive-style pages such as blog home, date archives, search results, 404, and post type archives
- Outputs the meta description tag in the frontend head when a description is available
- Uses the custom meta title as the document title when one is available
== Installation ==
1. Upload the plugin ZIP file in WordPress.
2. Activate the plugin.
3. Go to Ansico WP Basic > Settings.
4. Choose which post types should have SEO fields.
== Changelog ==
= 1.1.0 =
- Improved search result preview styling
- Made meta description output always active
- Removed title and description output toggles from settings
- Added support for author archives
- Added support for taxonomy term archives
- Added settings for archive and special pages
= 1.0.0 =
- Initial release