Automatically use Product Title for Focus Key Word and Image Attributes

#602536
  • Resolved Anonymous
    Rank Math free

    I would like to use the Woocommerce product title as the focus keyword, and image alt text, title, caption and description.

    I read the post How to Automate the Insertion of Focus Keyword however did not find the option for using the product title as the keyword.

    I do not have a lot of website experience so instructions on how to input codes is helpful.

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for your query and we are so sorry about the trouble this must have caused.

    You can use the following to get the product title added as the focus keyword for the products:

    
    function update_focus_keywords() {
        $posts = get_posts(array(
        'posts_per_page'    => -1,
        'post_type'     => 'product' // Replace post with the name of your post type
        ));
        foreach($posts as $p){
            // Checks if Rank Math keyword already exists and only updates if it doesn't have it
            $rank_math_keyword = get_post_meta( $p->ID, 'rank_math_focus_keyword', true );
        if ( ! $rank_math_keyword ){ 
                update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID)));
            }
        }
    }
    add_action( 'init', 'update_focus_keywords' );
    

    To add the code you can use one of the methods mentioned here: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Don’t hesitate to get in touch if you have any other questions.

    Anonymous
    Rank Math free

    thanks!

    Hello,
    
    You’re welcome.

    We are super happy that we have addressed your concern. If you have any other questions in the future, know that we are here to help you.
    
    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.
    
    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
    
    Thank you.

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

The ticket ‘Automatically use Product Title for Focus Key Word and Image Attributes’ is closed to new replies.