Dynamic Meta Descriptions

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Get Involved
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
gery1977
Registered User
Posts: 20
Joined: Sun Sep 18, 2011 4:59 pm

Re: Dynamic Meta Descriptions

Post by gery1977 »

Hi and thanks for your help,
Unfortunatedly the code produces and error when implemented. The error: Parse error: syntax error, unexpected ';' in /home4/syaacouk/public_html/Forum/viewtopic.php on line 1592 is displayed.

thanks again Callum
gery1977
Registered User
Posts: 20
Joined: Sun Sep 18, 2011 4:59 pm

Re: Dynamic Meta Descriptions

Post by gery1977 »

I fixed the problem by removing the extra ; but am unsure if the original edits are still required?

thanks Callum
User avatar
AmigoJack
Registered User
Posts: 5799
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Dynamic Meta Descriptions

Post by AmigoJack »

gery1977 wrote:fixed the problem by removing the extra ;
My fault - that one was indeed wrong. I also missed actually selecting the text of the post, so I updated my post. Now it's also tested.
gery1977 wrote:but am unsure if the original edits are still required?
Not in the PHP file. But you have to augment your style files nonetheless:
AmigoJack wrote:For every style you use open /styles/?/template/overall_header.html and find
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
gery1977
Registered User
Posts: 20
Joined: Sun Sep 18, 2011 4:59 pm

Re: Dynamic Meta Descriptions

Post by gery1977 »

Thanks for your help AmigoJack it is really appreciated. The code works to a degree. To explain here is a url to a topic l created: http://www.syaa.co.uk/Forum/viewtopic.php?f=1&t=2. On pages 1,2 & 3 of the topic the code acts as it should but on pages 4 & 5 the data changes. At the very top right of each page the data is echoed out so you can see what l mean. Any idea what is causing this?

thanks Callum
User avatar
AmigoJack
Registered User
Posts: 5799
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Dynamic Meta Descriptions

Post by AmigoJack »

Updated my post again. As you may have noticed: when crossing half of the posts in a topic, the last post is used instead of the first one. ;)
Could have been simpler, but I wanted to take into account all filters and sortings.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
gery1977
Registered User
Posts: 20
Joined: Sun Sep 18, 2011 4:59 pm

Re: Dynamic Meta Descriptions

Post by gery1977 »

That one worked perfectly! Thank you very much!

thanks again Callum
jano_s
Registered User
Posts: 16
Joined: Mon Dec 12, 2011 7:01 am
Contact:

Re: Dynamic Meta Descriptions

Post by jano_s »

Hello,
any idea how to generate dynamic meta description (or manualy, but which works with that MOD) for index.php (Board index), forums and categories?
The easiest way is add to meta in overall_header.html:

Code: Select all

<meta name="description" content="{S_META_DESCRIPTION}, YOUR_META_DESCRIPT" />
<meta name="keywords" content="{S_META_KEYWORDS}, YOUR_KEYWORDS" />
And then for index.php (Board index), forums and categories will appear YOUR_META_DESCRIPT and YOUR_KEYWORDS as meta. But in topics will it appear too - {S_META_DESCRIPTION}, YOUR_META_DESCRIPT (but I don't want it). Any ideas?
Thank you.
Mechatronics forum - discussions about mechatronics, related topics, studies, courses, books, your constructions What is mechatronics
User avatar
AmigoJack
Registered User
Posts: 5799
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Dynamic Meta Descriptions

Post by AmigoJack »

jano_s wrote:The easiest way is add to meta in overall_header.html:

Code: Select all

<meta name="description" content="{S_META_DESCRIPTION}, YOUR_META_DESCRIPT" />
<meta name="keywords" content="{S_META_KEYWORDS}, YOUR_KEYWORDS" />
No - just edit /index.php and /viewforum.php accordingly to my post. Do not touch the template files as you suggested it yourself.
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
lamvt
Registered User
Posts: 4
Joined: Tue May 10, 2011 3:50 am

Dynamic Meta Descriptions phpBB with UTF-8 support

Post by lamvt »

Great workd! keep warm.
What happen with UTF-8 , your code will clean it for meta keyword.
and I remove email address for keywords too

if you have problem with UTF-8 pls use code for viewtopic.php

Code: Select all

//lamvt
	        /*** 2011-03-03 BEGIN AmigoJack
            Dynamic meta description and meta keywords for topics, based on the first post ***/
        if( !$sMetaDescription ) {
            $sMetaDescription= preg_replace
                    ( array
                            ( '#\\[([^/\\]=]+)[^\\]]*\\]#'  // Strip possible BBCode opening tags
                            , '#\\[/[^\\]]*\\]#'  // Closing tags
                            , '#<[^>]+>#'  // Strip possible HTML
                            , '#[\\n\\r\\t]#s'  // Strip linebreaks and tabs
                            , '# +#'  // Strip multiple spaces
                            , '#[a-z]+(:|\\&\\#58;)\\S+#i'  // Strip URIs
                            , '#[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}#i'  // Strip Email
                            //, '#-#i'  // Strip -
                            //, '#:#i'  // Strip /
							//, '#,#i'  // Strip )
                            //, '#\(\#i'  // Strip )
                            )
                    , array
                            ( ''
                            , ''
                            , ''
                            , ' '
                            , ' '
                            , ' '
                            , ''
                          //  , ' '
							//, ''
							//, ''
							//, ' '
                            )
                    , $message
                    );
$sKeyWord= preg_replace
                    ( array
                            ( '#\\[([^/\\]=]+)[^\\]]*\\]#'  // Strip possible BBCode opening tags
                            , '#\\[/[^\\]]*\\]#'  // Closing tags
                            , '#<[^>]+>#'  // Strip possible HTML
                            , '#[\\n\\r\\t]#s'  // Strip linebreaks and tabs
                            , '# +#'  // Strip multiple spaces
                            , '#[a-z]+(:|\\&\\#58;)\\S+#i'  // Strip URIs
                            , '#[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}#i'  // Strip Email
                            , '#-#i'  // Strip -
                            , '#:#i'  // Strip /
							, '#,#i'  // Strip )
                            //, '#\(\#i'  // Strip )
                            )
                    , array
                            ( ''
                            , ''
                            , ''
                            , ' '
                            , ' '
                            , ' '
                            , ''
                            , ' '
							, ''
							, ''
							//, ' '
                            )
                    , $message
                    );
            // Keywords must be latin letters, ciphers and underscores only. Need to be more than 3 characters.
			
            $sKeyWord= ucwords( strtolower( $sKeyWord ) );
			if( ( strlen( $sKeyWord )> 250 )&& ( $iSpace= strpos( $sKeyWord, ' ', 250 ) )!== FALSE ) $sKeyWord= substr( $sKeyWord, 0, $iSpace );
        
					
            $aKeyWord= explode( ' ', $sKeyWord );
            $aDistinct= array();
            foreach( $aKeyWord as $v1 ) if( !isset( $aDistinct[$v1] )&& strlen( $v1 )> 3 ) $aDistinct[$v1]= 0;
            $sKeyWord= implode( ', ', array_keys( $aDistinct ) );

            // Shorten description if it's longer than 150 characters
            if( ( strlen( $sMetaDescription )> 400 )&& ( $iSpace= strpos( $sMetaDescription, ' ', 400 ) )!== FALSE ) $sMetaDescription= substr( $sMetaDescription, 0, $iSpace );
        }
        /*** 2011-03-03 END ***/ //lamvt
	
and header-overal.html use this code because if index page and forum page will havent keywords and descriptions

Code: Select all

<!-- IF S_TOPIC_ID -->
    <meta name="keywords" content="{S_META_KEYWORDS}" />
    <meta name="description" content="{S_META_DESCRIPTION}" />
<!-- ELSE -->
<meta name="keywords" content="{PAGE_TITLE}, {SITENAME}" />
<meta name="description" content="{PAGE_TITLE}, {SITENAME}" />
<!-- ENDIF -->
check DEMO here: Vietnam Inssurance news
Goodluck
[url=http://tin%20baohiem.com]Thông tin bảo hiểm Việt Nam[/url]
[url=http://tin%20baohiem.com]Vietnam insurance News[/url]
User avatar
Oyabun1
Former Team Member
Posts: 23162
Joined: Sun May 17, 2009 1:05 pm
Location: Australia
Name: Bill

Re: Dynamic Meta Descriptions

Post by Oyabun1 »

@ lamvt

Please explain why you have increased the meta tag length to 400 characters in the code when that far exceeds the maximum shown by the major search engines: Google = 156 characters, Yahoo = 161, Bing = 178.
                      Support Request Template
3.0.x: Knowledge Base Styles Support MOD Requests
3.1.x: Knowledge BaseStyles SupportExtension Requests
User avatar
AmigoJack
Registered User
Posts: 5799
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Dynamic Meta Descriptions

Post by AmigoJack »

Oyabun1 wrote:400 characters in the code
Well, he's somehow right, since strlen() counts bytes, not characters. I will change my code to use utf8_strlen() instead, which then really refers to characters, not bytes - hence there is no need for 400 bytes anymore (which gives only 200 or 133 vietnamese characters).
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
bala242
Registered User
Posts: 21
Joined: Mon Dec 26, 2011 6:09 am

Re: Dynamic Meta Descriptions

Post by bala242 »

thx AmigoJack great script it work like mod

but no meta tag/description in home page(index page)/form
it work only in topics
and how to remove viewtopic in tittle
pls help@thankx
User avatar
AmigoJack
Registered User
Posts: 5799
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Dynamic Meta Descriptions

Post by AmigoJack »

bala242 wrote:meta tag/description in home page(index page)
Dynamic keywords or descriptions for the index makes little to no sense. Use something hardcoded instead, like described in this post.
bala242 wrote:remove viewtopic in tittle
Remove 'View Topic' and 'View Forum' From Titles
  • The worst thing about censorship is ███████████
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
bala242
Registered User
Posts: 21
Joined: Mon Dec 26, 2011 6:09 am

Re: Dynamic Meta Descriptions

Post by bala242 »

AmigoJack wrote:
bala242 wrote:meta tag/description in home page(index page)
Dynamic keywords or descriptions for the index makes little to no sense. Use something hardcoded instead, like described in this post.
bala242 wrote:remove viewtopic in tittle
Remove 'View Topic' and 'View Forum' From Titles

thx friend now did meata tag for index.php and auto tag for every topics thx
it possible crate mod other phpbb members use it
Ondrasimus
Registered User
Posts: 1
Joined: Mon Jan 30, 2012 6:40 pm

Re: Dynamic Meta Descriptions

Post by Ondrasimus »

hi, pls its possible to allow other language characters? iam from czech rep and we have special characters in word (ěščřžýáí). When i aplicate your patch, these characters (ěščřžýáí) in topics are removed. :(
thanks
Locked

Return to “[3.0.x] Support Forum”