title: Dynamic meta description and keywords - Wordpress PHP
body: <p>I have this code that creates a dynamic page title in a Wordpress template page:</p>
  
  <pre><code>$prodname = sanitize_text_field($_GET['prod_name']);
  
  $prodname = esc_sql( $prodname );
  
  global $wpdb;
  $products = $wpdb-&gt;get_results("SELECT * FROM product_data WHERE prod_name='$prodname';");
  
  add_filter('wp_title', 'assignPageTitle');
  
  function assignPageTitle() {
  
      global $products;
  
      foreach($products as $product){
  
          echo "".$product-&gt;prod_page_title."";
  
      }
  
  }
  </code></pre>
  
  <p>I would like to use a similar technique to do meta description and meta keywords too, but i'm not sure what the Wordpress hooks are for those two. Anyone able to help?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>This code works to add meta description and meta keywords just before the closing <code>&lt;/head&gt;</code> tag</p>
  
  <pre><code>add_action( 'wp_head', 'assignMetaInfo' );
  
  function assignMetaInfo() {
  
      global $products;
  
      foreach($products as $product){
  
          echo "&lt;meta name='description' content='Test Description' /&gt;";
  
          echo "&lt;meta name='keywords' content='Test Keywords' /&gt;";
  
      }
  
  }
  </code></pre>