-
Can i set up auto focus keyword on pages ? Ex if i have 2000 pages ?
-
Hello,
Thanks for contacting us and sorry for any inconvenience that might have been caused due to that.
Please use the filter given below in your theme’s functions.php file to set the title of your pages 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' => 'page' //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');Hope this helps. Let us know if you need any other assistance.
hello i try but they give me error can you hellp me please ? This is the functions.php file :
<?php
/**
* GeneratePress.
*
* Please do not make any edits to this file. All edits should be done in a child theme.
*
* @package GeneratePress
*/if ( ! defined( ‘ABSPATH’ ) ) {
exit; // Exit if accessed directly.
}// Set our theme version.
define( ‘GENERATE_VERSION’, ‘3.1.0’ );if ( ! function_exists( ‘generate_setup’ ) ) {
add_action( ‘after_setup_theme’, ‘generate_setup’ );
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @since 0.1
*/
function generate_setup() {
// Make theme available for translation.
load_theme_textdomain( ‘generatepress’ );// Add theme support for various features.
add_theme_support( ‘automatic-feed-links’ );
add_theme_support( ‘post-thumbnails’ );
add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘video’, ‘quote’, ‘link’, ‘status’ ) );
add_theme_support( ‘woocommerce’ );
add_theme_support( ‘title-tag’ );
add_theme_support( ‘html5’, array( ‘search-form’, ‘comment-form’, ‘comment-list’, ‘gallery’, ‘caption’, ‘script’, ‘style’ ) );
add_theme_support( ‘customize-selective-refresh-widgets’ );
add_theme_support( ‘align-wide’ );
add_theme_support( ‘responsive-embeds’ );$color_palette = generate_get_editor_color_palette();
if ( ! empty( $color_palette ) ) {
add_theme_support( ‘editor-color-palette’, $color_palette );
}add_theme_support(
‘custom-logo’,
array(
‘height’ => 70,
‘width’ => 350,
‘flex-height’ => true,
‘flex-width’ => true,
)
);// Register primary menu.
register_nav_menus(
array(
‘primary’ => __( ‘Primary Menu’, ‘generatepress’ ),
)
);/**
* Set the content width to something large
* We set a more accurate width in generate_smart_content_width()
*/
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 1200; /* pixels */
}// This theme styles the visual editor to resemble the theme style.
add_editor_style( ‘assets/css/admin/editor-style.css’ );
}
}/**
* Get all necessary theme files
*/
$theme_dir = get_template_directory();require $theme_dir . ‘/inc/theme-functions.php’;
require $theme_dir . ‘/inc/defaults.php’;
require $theme_dir . ‘/inc/class-css.php’;
require $theme_dir . ‘/inc/css-output.php’;
require $theme_dir . ‘/inc/general.php’;
require $theme_dir . ‘/inc/customizer.php’;
require $theme_dir . ‘/inc/markup.php’;
require $theme_dir . ‘/inc/typography.php’;
require $theme_dir . ‘/inc/plugin-compat.php’;
require $theme_dir . ‘/inc/block-editor.php’;
require $theme_dir . ‘/inc/class-typography.php’;
require $theme_dir . ‘/inc/class-typography-migration.php’;
require $theme_dir . ‘/inc/class-html-attributes.php’;
require $theme_dir . ‘/inc/class-theme-update.php’;
require $theme_dir . ‘/inc/class-rest.php’;
require $theme_dir . ‘/inc/deprecated.php’;if ( is_admin() ) {
require $theme_dir . ‘/inc/meta-box.php’;
require $theme_dir . ‘/inc/class-dashboard.php’;
}/**
* Load our theme structure
*/
require $theme_dir . ‘/inc/structure/archives.php’;
require $theme_dir . ‘/inc/structure/comments.php’;
require $theme_dir . ‘/inc/structure/featured-images.php’;
require $theme_dir . ‘/inc/structure/footer.php’;
require $theme_dir . ‘/inc/structure/header.php’;
require $theme_dir . ‘/inc/structure/navigation.php’;
require $theme_dir . ‘/inc/structure/post-meta.php’;
require $theme_dir . ‘/inc/structure/sidebars.php’;Hello,
It seems like you’re making the changes in the parent theme and you already have a child theme.
Please add the code in the functions.php file of your child theme and see if the issue gets fixed.
You can also follow this guide for alternate ways of adding the code:
https://rankmath.com/kb/wordpress-hooks-actions-filters/Please let us know how that goes.
Thank you.
Οκ….Awesome support ❤ 💙 ♥
Hello,
We’re glad that we could address the concern.
Please feel free to get in touch if you require any further assistance.
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.
The ticket ‘Can i set up auto focus keyword on pages ? Ex if i have 2000 pages’ is closed to new replies.