WordPress.org

Forums

Can I put the_excerpt in my head <description> tag? (6 posts)

  1. Mark Bloomfield
    Member
    Posted 10 years ago #

    Hi All..

    For SEO reasons, I'd like to be able to (when viewing a single article) have the excerpt of that article in my meta 'description' tag of the header.

    I assume there'd have to be a <?php ?> command that'll pull this in from the database..

    Can anyone guide me as to what this command would be??

    Thanks very much

  2. Kafkaesqui

    Posted 10 years ago #

    See this plugin of mine:

    http://wordpress.org/support/topic/35875#post-203626

    Note it has two user variables now: $post_desc_length, which sets the length of the description in words; $post_use_excerpt, which tells the plugin to use the excerpt text if it exists, or force the use of the post's content at all times.

  3. Mark Bloomfield
    Member
    Posted 10 years ago #

    Perfect that works.. thanks Kafkaesqui...

    another question.. you mention i can set the amount of words etc.. how do i do that?? do you have an example line of code that'll show me my options??

    i have limited php knowledge..

    thank you :)

  4. Kafkaesqui

    Posted 10 years ago #

    If you can edit the plugin files online, go to Plugins > Plugin Editor in your WordPress admin pages, and select Head Meta Description*. Right after the

    function head_meta_desc() {

    line in the plugin, you'll see

    $post_desc_length = 20; // description length in # words

    Change the value of $post_desc_length to the number of words you want displayed in your description.

     
    * You can edit it offline as well, and then upload the modified version.

  5. Mark Bloomfield
    Member
    Posted 10 years ago #

    !doh...

    why'dn't i think of that.. :)

    another spanner in the works.. would it be possible to have a default description? for example on the index page, there is now no description because of the lack of a excerpt..

    any suggestions??

  6. Kafkaesqui

    Posted 10 years ago #

    A spanner? Nah...Actually, the script already outputs a description for:

    - posts and Pages => abbreviation of excerpt or content
    - category queries => category description
    - everything else => blog "tagline"

    Possibly the only things missing are the ability to override single posts/Pages with a custom field, and a different default description than the blog's tagline. Easy peasy:

    http://guff.szub.net/downloads/head-meta-desc.zip

    Version 0.4 now has 4 user-configurable variables:

    $default_blog_desc
    Default description (if set, will override use of blog tagline).

    $post_desc_length
    Length in # of words for a post/Page description.

    $post_use_excerpt
    1 (default) = use excerpt (if exists) for description. 0 = force use of content at all times.

    $custom_desc_key
    Custom field key; if exists, overrides use of excerpt/content for post/Page description.

    Have fun. :)

Topic Closed

This topic has been closed to new replies.

About this Topic