SEO Metatag Info - fine plugin with extensive functions

Find help with FlatPress plugins, report a plugin bug, request or present new plugins.
User avatar
Arvid
FlatPress Coder
Posts: 629
Joined: Sat Jan 26, 2019 7:40 pm
Contact:

Re: SEO Metatag Info - fine plugin with extensive functions

Post by Arvid » Mon Dec 12, 2022 7:38 pm

Happy to see the community working together - thanks to both of you! 8-)

wjar
Posts: 10
Joined: Sun Jun 29, 2025 3:07 pm

Re: SEO Metatag Info - fine plugin with extensive functions

Post by wjar » Sun Aug 31, 2025 3:16 pm

Is it possible using a variable of the Plugin in the template, e.g. using $seo_desc as introduction for a post?

User avatar
fraenkiman
Posts: 470
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: SEO Metatag Info - fine plugin with extensive functions

Post by fraenkiman » Sun Aug 31, 2025 6:18 pm

Hello Wolfgang,

Out of the box, no. With a small hook, yes. The SEO plugin value is not assigned in Smarty. You could insert this function at the end of the plugin.seometataginfo.php file:

Code: Select all

/**
 * Make per-entry SEO meta available to Smarty templates.
 * Memorization reduces double reads within a request.
 * Exposes: $seo_desc, $seo_keywords for the current entry block.
 * For output in the template, e.g. in entry-default.tpl:
 *   {if $seo_desc}<i>{$seo_desc|escape}</i>{/if}
 *   {if $seo_keywords}<i>{$seo_keywords|escape}</i>{/if}
 */
function seometataginfo_assign_entry_vars($id) {
	if (!is_string($id) || $id === '') return;
	static $memo = array();
	if (isset($memo [$id])) {
		if (isset($GLOBALS ['smarty']) && is_object($GLOBALS ['smarty']) && method_exists($GLOBALS ['smarty'], 'assign')) {
			$GLOBALS ['smarty']->assign('seo_desc', $memo [$id] [0]);
			$GLOBALS ['smarty']->assign('seo_keywords', $memo [$id] [1]);
		}
		return;
	}
	$file_meta = SEOMETA_ENTRY_DIR . $id . '_metatags.ini';
	
	// Ensure $smarty is usable
	if (!isset($GLOBALS ['smarty']) || !is_object($GLOBALS ['smarty']) || !method_exists($GLOBALS ['smarty'], 'assign')) {
		return;
	}
	$smarty = $GLOBALS ['smarty'];
	if (!is_readable($file_meta)) {
		$memo [$id] = array('', '');
		$smarty->assign('seo_desc', '');
		$smarty->assign('seo_keywords', '');
		return;
	}
	$cfg = new iniParser($file_meta);
	$descRaw = $cfg->get('meta', 'description');
	$keysRaw = $cfg->get('meta', 'keywords');
	$seo_desc = $descRaw !== false ? wp_specialchars(trim((string)$descRaw)) : '';
	$seo_keywords = $keysRaw !== false ? wp_specialchars(trim((string)$keysRaw)) : '';
	$memo [$id] = array($seo_desc, $seo_keywords);
	$smarty->assign('seo_desc', $seo_desc);
	$smarty->assign('seo_keywords', $seo_keywords);
}

// Bind during entry rendering so {$seo_desc} and {$seo_keywords} is available inside {entry} blocks
add_action('entry_block', 'seometataginfo_assign_entry_vars', 0);
Then edit the entry-default.tpl file and insert

Code: Select all

{if $seo_desc}<i>{$seo_desc|escape}</i>{/if}
.
Screenshot 2025-08-31 200840.png
Screenshot 2025-08-31 200840.png (8.13 KiB) Viewed 25388 times
The result looks something like this:
Screenshot 2025-08-31 201403.png
Screenshot 2025-08-31 201403.png (45.28 KiB) Viewed 25388 times
Best regards,
Frank
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

wjar
Posts: 10
Joined: Sun Jun 29, 2025 3:07 pm

Re: SEO Metatag Info - fine plugin with extensive functions

Post by wjar » Mon Sep 01, 2025 5:49 pm

Hello Frank,

Thank you. I tried your solution but it's not working on my test environment. The following lines were added to the errorlog file:

[Mon Sep 01 18:27:36.406959 2025] [php:warn] [pid 4888] [client 127.0.0.1:39734] PHP Warning: Undefined array key "seo_desc" in /opt/lampp/htdocs/fp-content/compile/e93fccb09cf8b04111b9595da102f3f4^11ce5b354f64090b7f9eaa526de967b8bbcc8f6b_0.file.entry-default.tpl.php on line 46, referer: http://localhost/
[Mon Sep 01 18:27:36.406993 2025] [php:warn] [pid 4888] [client 127.0.0.1:39734] PHP Warning: Attempt to read property "value" on null in /opt/lampp/htdocs/fp-content/compile/e93fccb09cf8b04111b9595da102f3f4^11ce5b354f64090b7f9eaa526de967b8bbcc8f6b_0.file.entry-default.tpl.php on line 46, referer: http://localhost/

PHP version is 8.2.12

User avatar
fraenkiman
Posts: 470
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: SEO Metatag Info - fine plugin with extensive functions

Post by fraenkiman » Mon Sep 01, 2025 6:15 pm

Good evening Wolfgang,

I can't reproduce the error. You may have forgotten to clear the theme and template cache.

Feel free to download the plugin from FlatPress 1.5.dev and try it out. I had no entries in the PHP log under PHP 8.4.
seometataginfo2_2_5.zip
(31.02 KiB) Downloaded 126 times
Best regards,
Frank
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

User avatar
fraenkiman
Posts: 470
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: SEO Metatag Info - fine plugin with extensive functions

Post by fraenkiman » Mon Sep 01, 2025 6:57 pm

For safety's sake, here is the modified entry-default.tpl file for the leggero theme.
entry-default.zip
(822 Bytes) Downloaded 122 times
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

wjar
Posts: 10
Joined: Sun Jun 29, 2025 3:07 pm

Re: SEO Metatag Info - fine plugin with extensive functions

Post by wjar » Tue Sep 02, 2025 4:23 pm

Hello Frank,

Thank you, but even a new installation didn't make it better. I will try again on the weekend with the Flatpress version on Github.

Regards
Wolfgang

User avatar
fraenkiman
Posts: 470
Joined: Thu Feb 03, 2022 7:25 pm
Location: Berlin, Germany
Contact:

Re: SEO Metatag Info - fine plugin with extensive functions

Post by fraenkiman » Tue Sep 02, 2025 6:58 pm

Hmm, in FlatPress 1.4.1, Smarty compiles array accesses ($_tpl_vars[‘seo_desc’]), which I had overlooked or ignored until now.

I have also incorporated
seometataginfo2_2_5_smarty4.zip
(31.12 KiB) Downloaded 133 times
this patch into this version.

Code: Select all

// Establish compatibility with older Smarty 4.
function seometataginfo_assign_defaults() {
	if (isset($GLOBALS ['smarty']) && is_object($GLOBALS ['smarty']) && method_exists($GLOBALS ['smarty'], 'assign')) {
		$GLOBALS ['smarty']->assign('seo_desc', '');
		$GLOBALS ['smarty']->assign('seo_keywords', '');
	}
}
add_action('init', 'seometataginfo_assign_defaults', 0);
The template remains as in this comment.

This should allow it to work without Smarty4 errors.
:pencil: You are strong in PHP and Java Script? :point_right: Then help us to improve FlatPress. :point_left:

:exploding_head: Looking for ideas, templates, examples and answers to frequently asked questions?
:bulb: You'll find it here.

My :de: FlatPress-Blog: https://frank-web.dedyn.io

wjar
Posts: 10
Joined: Sun Jun 29, 2025 3:07 pm

Re: SEO Metatag Info - fine plugin with extensive functions

Post by wjar » Sat Sep 06, 2025 3:41 pm

Hello Frank,

Thank you, with the Git version it is working properly, the modification for Smarty 4 only eliminated the entry in the error log, but there was no output of the variables.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests