[SmartCrawl Pro] Tags as keywords as defualt

In individual posts, with Smartcrawl I can use the switch "Tags as keywords" for that post. Is there a setting for making this default for all posts, even existing ones?

  • Dimitris
    • Support Star

    Hello there Ove

    As there isn't any built-in option to enable "tags as keywords" for all posts or other post types, I've pinged our developers about it in case there's a hotfix that we could provide to you now, as well as if this could be a new feature added in SmartCrawl.

    We'll keep you posted here as soon as we've got some insights about these.

    Thank you,
    Dimitris

  • Panos
    • SLS

    Hi Ove !

    In order to force the "Tags As Keywords" option for each new post and page you can try out the following snippet:

    add_action( 'wp_insert_post', function( $post_ID, $post, $update ){
    
    	$post_types = array( 'post', 'page' );
    
    	if ( $update || ! in_array( $post->post_type, $post_types ) ) {
    		return;
    	}
    
    	update_post_meta( $post_ID, '_wds_tags_to_keywords', true );
    
    }, 20, 3 );

    That will set that meta option when a new post or page is created. If you want to add more post types you can add them in this line:
    $post_types = array( 'post', 'page' );
    If you want this to be applied in all post types you can remove the post type check completely by changing this line:
    if ( $update || ! in_array( $post->post_type, $post_types ) ) {
    to
    if ( $update ) {

    In case you have existing posts and want to update that option in bulk for those, you can try out the following snippet:

    add_action( 'admin_init', function(){
    
    	if ( ! isset( $_GET['action'] ) || 'tags_to_keyword_posts' != $_GET['action'] ) {
    		return;
    	}
    
    	$post_types = array( 'post', 'page' );
    
    	$posts = get_posts(array(
    		'post_type' 		=> $post_types,
    	  	'numberposts' 		=> -1,
    	  	'post_status' 		=> 'any',
    
    	));
    
    	foreach ( $posts as $key => $post ) {
    		update_post_meta( $post->ID, '_wds_tags_to_keywords', true );
    	}
    } );

    This will run when you visit this admin page:
    yoursite.com/wp-admin/?action=tags_to_keyword_posts

    If you want to add more post type you can add them in this line:
    $post_types = array( 'post', 'page' );

    In case you have a huge number of posts, like thousands of them, it would be better to run this via ajax so it doesn't time.In such case please let us know so we can modify the script.

    After running the second snippet, the existing posts should be updated, so you don't need that anymore. You either comment it out or delete it completely.

    You can add the above snippets in a mu-plugin, which if you are not familiar with, you can read about here :
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/
    In case you prefer you can use your child theme's functions.php file instead, however make sure you are using a child theme so you don't lose your changes.

    If this is out of your comfort zone we would be happy to add these snippets in your site but we would need admin and ftp access. You can share that privately through our contact form: https://premium.wpmudev.org/contact/#i-have-a-different-question

    Send in:Subject: "Attn: Panos Lyrakis"

    - Admin login:
    Admin username
    Admin password
    Login url

    - FTP credentials
    host
    username
    password
    (and port if required)

    - link back to this thread for reference

    If you need to include exclude post types you can add this in your message too.

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.