Can you add “Buy” in front of %title% in focus keyword? (with Functions code)

#366660
  • Resolved Pipi
    Rank Math free

    From https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/

    Automatically Use the Post Title as the Focus Keyword

    /**
     * Function to automatically update the focus keyword with the post title
     */
    function update_focus_keywords()
    {
        $posts = get_posts(array(
            'posts_per_page'    => -1,
            'post_type'        => 'post' //replace post with the name of your post type
        ));
        foreach ($posts as $p) {
            update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
        }
    }
    add_action('init', 'update_focus_keywords');

    Is it possible to insert word “Buy” in front of every Focus Keyword? Basically right now it would use title of the product, I assume this code will work for products too? So if the product is called “Nike Shoes” then Focus Keyword would be “Nike Shoes”. I am wondering if it’s possible to add to this automatization “Buy %Title%” so “Buy Nike Shoes”. (I know %title% doesn’t work for focus keyword, just an example)

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Pipi
    Rank Math free

    ignore, double post

    Pipi
    Rank Math free

    Sorry for mess in posts but editing sometimes doesn’t let me edit it properly.

    The code I am using right now that does work for products (code comes from one of your employees that helped someone with same issue

    $posts = get_posts( array(
            'posts_per_page' => 100,
            'post_type' => 'product',
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => 'rank_math_focus_keyword',
                    'compare' => 'NOT EXISTS',
                ),
                array(
                    'key'     => 'rank_math_focus_keyword',
                    'value'   => '',
                    'compare' => '='
                ),
            )
        ) );
        foreach( $posts as $post ) {
            update_post_meta( $post->ID, 'rank_math_focus_keyword', $post->post_title );
        }

    So it does work. And my question stands, is it somehow possible to insert before the title word “Buy”?

    Pipi
    Rank Math free

    Issue resolved with plugin Wp Sheet Editor

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    We are glad that you have already managed to resolve this issue.

    If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.

    Looking forward to helping you.

    Thank you.

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

The ticket ‘Can you add “Buy” in front of %title% in focus keyword? (with Functions code)’ is closed to new replies.