Jump to content

Change Announcement meta tags and page title


weelow

Recommended Posts

Hello,

I am trying to find an easy way to change the announcements page title according to the article title, just like knowledge base, and maybe excerpt the data to get a summary for the description for the purpose of SEO. Any ideas?

The plugin below, is what i want to achieve. It is no longer available but you can check the screen shots to get an idea.

https://marketplace.whmcs.com/product/3887-hook-announcement-and-product-title

Link to comment
Share on other sites

<?php

add_hook('ClientAreaHeadOutput', 1, function($vars)
{
    if ($vars['templatefile'] == 'viewannouncement')
    {
    return <<<HTML
<meta name="description" content="{$vars['summary']}">
HTML;
    }
});

add_hook('ClientAreaPageAnnouncements', 1, function($vars)
{
    return array('pagetitle' => $vars['title']);
});

To be honest, there's almost no benefit in doing that due to the following reason:

  • Meta descriptions are not a ranking factor
  • Google "sees" WHMCS in default language only
  • Good meta descriptions can't be simply an excerpt
Link to comment
Share on other sites

I dumped the $vars to attempt to find the right one but I didnt spot this one. I will trying applying it and tell you how it goes.

The reason I want to do that is for sharing the article on social media or whatsapp

I want to be able to add the default og:image and og:title and so on.

Later on a module can be developed that adds feature to the announcement for SEO title and description. But I needed the right $vars to pull the article ID or anything useful to perform additional ditect database query or add a new seo table and relate them.

But for the time being have a proper title and an image will suffice for social media sharing.

Thanks Kian.

 

Link to comment
Share on other sites

So you need to implement Open Graph Protocol and not just Meta Description tag. In fact not all platforms use Meta Description when posting links. For example if I remember correctly, Facebook doesn't care or Meta Description, it looks for OG metas.

Edited by Kian
Link to comment
Share on other sites

That is exactly what I have in mind. It is really not useful to have this kind of announcement system when all announcements on what'sapp have the same title. Announcement-company. 😅. I just want to make it more useful.

Edited by weelow
Adding reason
Link to comment
Share on other sites

  • 2 years later...
On 6/4/2020 at 5:35 AM, Kian said:

<?php

add_hook('ClientAreaHeadOutput', 1, function($vars)
{
    if ($vars['templatefile'] == 'viewannouncement')
    {
    return <<<HTML
<meta name="description" content="{$vars['summary']}">
HTML;
    }
});

add_hook('ClientAreaPageAnnouncements', 1, function($vars)
{
    return array('pagetitle' => $vars['title']);
});

To be honest, there's almost no benefit in doing that due to the following reason:

  • Meta descriptions are not a ranking factor
  • Google "sees" WHMCS in default language only
  • Good meta descriptions can't be simply an excerpt

How can this same hook be repurposed for use on ALL pages?

Link to comment
Share on other sites

  • 11 months later...

<?php

add_hook('ClientAreaHeadOutput', 1, function($vars) {
    $uri_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $uri_segments = explode('/', $uri_path);
    $articleArr = array(
        1 => 'knowledgebase meta',
    );
    $annouArr = array(
        1 => "announcements meta",
    );
    $returnStr='';
    if ( array_key_exists($vars['kbarticle']['id'], $articleArr) ) {
        $meta = '<meta name="description" content="'.$articleArr[$vars['kbarticle']['id']].'">';
    }elseif($uri_segments[2] == 'announcements' && array_key_exists($vars['id'], $annouArr)){
        $meta = '<meta name="description" content="'.$annouArr[$vars['id']].'">';
    }else{
        $meta = '';
    }
    if (isset($meta) && !empty($meta)) {
        $returnStr .= $meta;
    }
    return $returnStr;
});

 

similar you can add title.
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated