Please upgrade here. These earlier versions are no longer being updated and have security issues.

Adding meta description to the forum home page.

pracddhapracddha New
edited November 2013 in Vanilla 2.0 - 2.3

I am using vanilla seo plugin and vanilla version 2.0.18.8 While this plugin does generates meta desc for all other pages, it doesn't give option to set meta desc for the home. But I want to write a one good meta desc for my homepage as well. Please help me on how can I do that (whether I use vanilla seo or not); just adding a custom meta description to home page.

Please don't take me to another post (saying this might help you or that might help you), because before asking this question, I have already made the search. While few have asked this question before, but none of those reply are very specific to this question.

Comments

  • hbfhbf wiki guy? MVP

    @pracddha said:
    I am using vanilla seo plugin and vanilla version 2.0.18.8 While this plugin does generates meta desc for all other pages, it doesn't give option to set meta desc for the home. But I want to write a one good meta desc for my homepage as well. Please help me on how can I do that (whether I use vanilla seo or not); just adding a custom meta description to home page.

    Please don't take me to another post (saying this might help you or that might help you), because before asking this question, I have already made the search. While few have asked this question before, but none of those reply are very specific to this question.

    ahh.. but there are so many good discussion about this topic out there already. i would love to point you toward them. oh well.

    you can accomplish this through any number of means:
    1) modify the seo plugin
    2) modify your theme
    3) create your own plugin
    4) well.... you get the idea. (right?)

  • pracddhapracddha New
    edited November 2013

    @hbf : 4) Create your own plugin....that is not an option for me. I am new to both coding and vanilla. However I can dig into pre-written codes and try to figure out the things and play/modify with them to bring out results (After trying a lot :P).

    2) I would love a code that would modify my theme without disturbing other aspects of already working theme & plugins. I just want to add that single line meta description to my homepage. Nothing else. I don't want that code to show in other pages, as Vanilla seo is already doing that.

    When i searched for things, they started with the title i mentioned but ended up discussing about "noindex, nofollow" & "meta description on custom pages" stuffs. That is not what i am looking for.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Well, if you don't like links, then I'll give you quotes ;)

    @x00 said:
    Something like in class.nofollowthemhooks.php

    <?php if (!defined('APPLICATION')) exit();
    class NofollowThemeHooks extends Gdn_Plugin{
    
      public function DiscussionController_Render_Before($Sender){
         $CategoryID = GetIncomingValue('vanilla_category_id', NULL);
         if(!$CategoryID)
            $CategoryID = GetValue('CategoryID', $Sender);
         if($CategoryID == C('Vanilla.Embed.DefaultCategoryID', 0)){
            $this->NoFollow($Sender);
         }
      }
    
      protected function NoFollow($Sender){
          $Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,follow'));
      }
    }
    

    drop it in your theme. It assumes you have set Vanilla.Embed.DefaultCategoryID

    @x00 said:
    use the eventi plugin to decide where you want to place the meta

    then read this

    http://vanillaforums.org/docs/plugins

    You could use a theme hook. See first quotation for how that could be done and the second quote for a hint to a helper that will show you where to hook.

    It is a feature of Vanilla that there is not a forced page as a homepage but you can choose. what page is your homepage. So if you tell us what you have choosen as your homepage, we would be able to give more specific hints for a non coder ;)


    hgtonight
  • hbfhbf wiki guy? MVP

    all of my plugins start as a copy paste from the most similar thing i can find. i never hit file->new

    R_Jhgtonight
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    So do I. And that's the way I've learned that you can enable a plugin although the $PluginInfo['YourPlugin'] string does not match, but you could not disable it because of that!


    peregrine
  • peregrineperegrine MVP
    edited November 2013

    @R_J said:
    So do I. And that's the way I've learned that you can enable a plugin although the $PluginInfo['YourPlugin'] string does not match, but you could not disable it because of that!

    yep the directory has to match. and it is case sensitive too. hbf knows that too ;)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • pracddhapracddha New
    edited November 2013

    @R_J thank you for the information. I am using "~/discussions" (all discussions) as my homepage. But I was wondering that just to add a custom meta discription of one line, just for that single page, I will have to add that whole chunk of code.

    Yes, this was the same code I was talking about

    @pracddha said:
    When i searched for things, they started with the title i mentioned but ended up discussing about "noindex, nofollow" & "meta description on custom pages" stuffs. That is not what i am looking for.

    which confused me. Check line 2, 13 and 14, it looks like this code has more to do with nofollow, noindex than adding meta desc. Its saying in line 14, add tag name="robots"...but where is code for description here.
    Or is it that I have to apply this code by replacing name="robots" by name="description" and content="{my custom description here}". Please help in applying it !

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    It's like you've already guessed. You'll have to change it to suit your needs...

    But if your description is static, the best way would be to add it to the default.master.tpl. Do you already have a custom theme with that file? The default.master.tplis a smarty file, so you would have to search for Smarty here. That's what I made up after some searching. You would have to put that in the head tag of your template

    {if $smarty.server.REQUEST_URI == '/discussions'}
    <meta>your meta her</meta>
    {/if}
    

    I have absolutely no idea of smarty, so that piece of code may not work at all. If it does not, try something like <!-- Request Url = {$smarty.server.REQUEST_URI} --> somewhere in the default.master.tpl and see if at least that is giving you the desired result...

    If you want dynamic content in the meta tag, then you should create a theme hook. I've never created one so you might have to search in the wiki or here in the forums on how to use it exactly, e.g. where to save it and under which filename. The code should look something like that:

    <?php if (!defined('APPLICATION')) exit();
    class YourThemeHooks extends Gdn_Plugin {
       public function DiscussionsController_Render_Before($Sender) {
          $Description = 'Build up your description string here';
          $Sender->Head->AddTag('meta', array('name' => 'description', 'content' => $description));
       }
    }
    

    Start, tell us when and where you get stuck, and we'll see if we can help you solving your problem


  • pracddhapracddha New
    edited November 2013

    @R_J : Just done with Facebook icon issue. Now its time to check with meta desc. Yes, I want to use static desc for that homepage. Beacause Vanilla SEO is dynamically producing title and desc for other pages. And homepage is always a important page of site and to be able to give a proper desc is necessary.

  • pracddhapracddha New
    edited November 2013

    @R_J are you saying something like this:

    ~~~

    <?php $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if($host == 'http://www.domainhostforum.com') {echo '<meta name="description" content="Domain Hosting Forum meta desc"/>'; } ?>

    ~~~

    >
    I kept this code within head tag after the code in default.master.php:
    >

    <?php $this->RenderAsset('Head'); ?>

    >
    But it didn't worked !

  • hgtonighthgtonight ∞ · New Moderator

    Use a themehook on HeadModule_BeforeToString_Handler. Inspect the request against the default controller destination. If it is true, add the meta tag through $Sender->AddTag()

    Something like this should work:

    public function HeadModule_BeforeToString_Handler($Sender) {
      $Path = Gdn::Request()->Path();
      $HomeRoute = Gdn::Router()->GetRoute('DefaultController');
      $HomePage = $HomeRoute['Destination'];
    
      if($Path == '' || $Path == $HomePage) {
        $Sender->AddTag('meta', array('name' => 'description', 'content' => 'This is a cool SEO homepage description'));
      }
    }
    

    You can't use Base_Render_Before because the head module is already rendered (through ToString) at that point.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    pracddha
  • pracddhapracddha New
    edited November 2013

    @hgtognight: While thanks for trying hard to explain me...but seriously your things are going over my head. Like I said I am new to coding and I can't digest terms like "themehook", "head module" and "controller destination", "base_render_before". Say it in a simple php terms. Even I am not pro at php. However I manage to modify things in pre-written php code for getting my results.

    @hgtonight said:
    You can't use Base_Render_Before because the head module is already rendered (through ToString) at that point.

    Where have I used that? That was a simple php code which first checked with if condition, what was the url of the page. And if url was that of homepage, meta tag was to be implemented (At least that was my plan). However the code didn't worked :p

    Now you wrote that piece of code and said, use a "themehook" on "headmodule". And then inspect against "default controller destination". What's that and how you inspect against it? Where shall I drop that code? Shall I wrap up with php and drop it inside head? Oh poor me !

  • peregrineperegrine MVP
    edited November 2013

    @pracddha

    you will do yourself a world of good and will learn, if you search a few threads for themehooks.

    how to do things is all layed out.

    if there is a term somebody mentions and you don;t know what it means or hot to do. sometimes searching on the forum will give you more insights.

    there is a wiki as well - there may very well be article on this topic.

    and there are articles on using events.

    edited: I see hgtonight gave you the answer, but the wiki and the search box can help you familiarize yourself with terms you may not understand.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    UnderDog
  • hgtonighthgtonight ∞ · New Moderator
    edited November 2013

    Theme hooks is a class that gets run with a theme and acts like a plugin: http://vanillawiki.homebrewforums.net/index.php/Theme_Hooks

    The function I gave you "hooks" into the head module right when the "BeforeToString" event is fired and executes. What the function does is get the current path, get the homepage path, and if the two are the same (or the path is empty) it adds a tag to the head module ($Sender in this case).

    Plop the function in your theme hooks file and change 'This is a cool SEO homepage description' to any valid PHP string that describes your homepage.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    pracddhaUnderDog
  • pracddhapracddha New
    edited November 2013

    @R_J, @hgtonight, @UnderDog @peregrine @hbf: Finally the code worked today:
    The reason the code in http://vanillaforums.org/discussion/25410/adding-meta-description-to-the-forum-home-page#Comment_196843 didn't work is I added that "http://" and didn't added "/" after end of url. So, after correcting it, the working code is here:

    ~~~

    <?php $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if($host == 'www.yourdomainname.com/') { echo "\n" echo '<meta name="description" content="Put Your Meta description here"/>'; } ?>

    ~~~

    Now put this code in default.master.php inside <head></head> . You can put it just below this code there: <?php $this->RenderAsset('Head'); ?>

    The reason I used echo "\n" in the code is to bring this meta description in new line. You may or may not add this line (your wish). Because this really don't matter. But don't use <br /> for it. Also, in your case you may or may not use "www." in the url.

    Finally done with meta description in home page as well ! :)

Sign In or Register to comment.