bbpress Automate the Insertion of Focus Keyword

#447226
  • Resolved Uk Sentinel
    Rank Math free

    Hi

    I am experimenting with Rank Math and have seen the thread to Automate the Insertion of Focus Keyword for WordPress post.

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

    I use BBPRESS and wish to Automate the Insertion of Focus Keyword for all my BBPRESS Topics and Replies.

    I have already added Focus keywords for my BBPRESS Forums and do not wish for them to be replaced.

    Just the BBPRESS Topics and Replies need to be automated

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math.

    You can use the code for the topics and replies, you only need to set the post_type to topic and reply in the code.

    /**
     * Function to automatically update the focus keyword with the post title, if no focus keyword is set
     */
    function update_focus_keywords() {
        $posts = get_posts(array(
        'posts_per_page'	=> -1,
        'post_type'		=> 'reply' // 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' );

    Hope this helps.

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

    Hi

    When I insert the above code twice, one with ‘reply’ and the other with ‘topic’ I get the following php error

    Can both Reply and Topic be included in a single code string etc.

    ‘post_type’ => ‘reply’

    and then
    ‘post_type’ => ‘topic’

    ——

    Your PHP code changes were rolled back due to an error on line 255 of file wp-content/themes/timesnews/functions.php. Please fix and try saving again.

    Cannot redeclare update_focus_keywords() (previously declared in wp-content/themes/timesnews/functions.php:238)
    ——

    line 255 is

    function update_focus_keywords() {

    I have found using that code has unfortunately increased the time it takes to open a topic or thread from .75s to over 2s

    I will not proceed with this idea and thank you for your time

    Hello,

    We are super happy that you are able to resolve it.

    If you 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.

    UK-Sentinel
    Rank Math free

    Hi

    Can you add both Reply and Topic to be included in a single code string etc.

    How would I code this as per above example ?

    ‘post_type’ => ‘reply’

    and then
    ‘post_type’ => ‘topic’

    Anas
    Rank Math business

    Hello,

    You can use the same code for the other post types.

    Once the focus keywords are added to the topics, you can replace the post type with reply.

    Hope this helps.

    We look forward to helping you.

    UK-Sentinel
    Rank Math free

    Thank you

    Anas
    Rank Math business

    Hello,

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘bbpress Automate the Insertion of Focus Keyword’ is closed to new replies.