• Resolved martyn

    (@marty2010)


    Hi there,
    I’m testing your theme and is fast and light, I’m satisfied.
    I have only a problem.
    Usually I use a function to get a meta description automatically generated (get the_content) if its custom field is empty, but it doesn’t work with generatepress.
    So I have found the function below in your forum and I tried many times to modify it for my need, but dont know how to.
    In case I can write my ‘usual’ function.
    I will greatly appreciate your suggestion.

    function my_description() {
    if ( is_single() || is_page() || is_category() || is_product() ) {
            $meta_desc = get_post_meta( get_the_ID(), 'description', true );
    
    if ( $meta_desc ) {
                printf( '<meta name="description" content="%s">', $meta_desc );
            }
       }
    }
    add_action('wp_head', 'my_description', 1);
Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Tom

    (@edge22)

    Hi there,

    That function should work with any theme, as it’s just looking for a custom field and outputting the value if it exists.

    It won’t work for is_category(), as custom fields don’t exist there.

    However, it will work for the other posts and pages as long as a custom field with the name description exists.

    If you want it to be automatic, you would need to use something like get_the_excerpt() instead of the custom field.

    Let me know 🙂

    Thread Starter martyn

    (@marty2010)

    Ok, thank you!
    solved

    Theme Author Tom

    (@edge22)

    No problem 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘auto meta description page, single, product’ is closed to new replies.