1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Changing the Meta Tags

Discussion in 'Developing Plugins' started by Nick, Oct 13, 2009.

  1. Nick

    Nick Well-Known Member

    You can dynamically change a page's meta tags from a plugin by including a function for the header_meta hook.

    Here are two real examples. The first is from the Submit plugin which uses a post's content for the description tag. The second is from the Tags plugin which uses a post's tags as meta keywords.

    PHP:
        /**
         * Match meta tag to a post's description (keywords is done in the Tags plugin)
         */
        
    public function header_meta($h)
        {    
            if (
    $h->pageType == 'post') {
                echo 
    '<meta name="description" content="' $h->post->content '">' "\n";
                return 
    true;
            }
        }
    PHP:
        /**
         * Match meta tag to a post's keywords (description is done in the SB Base plugin)
         */
        
    public function header_meta($h)
        {
            if (
    $h->pageType != 'post') { return false; }
            
    $meta_content sanitize($h->post->content'all');
            
    $meta_content truncate($meta_content200);
            echo 
    '<meta name="description" content="' $meta_content '" />' "\n";
            return 
    true;
        }
     

Share This Page