Skip to content

Instantly share code, notes, and snippets.

@freddielore
Last active March 14, 2022 02:59
Show Gist options
  • Select an option

  • Save freddielore/9d53b956c73cbefb36b85e840628cd0a to your computer and use it in GitHub Desktop.

Select an option

Save freddielore/9d53b956c73cbefb36b85e840628cd0a to your computer and use it in GitHub Desktop.

Revisions

  1. freddielore revised this gist Mar 14, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions smart-seo-tags-categories.php
    Original file line number Diff line number Diff line change
    @@ -23,16 +23,16 @@ function child_theme_callback_tags( $post ){
    return '';
    }

    // also process `categories` and `tags` columns during CSV import
    // to process `categories` and `tags` columns during CSV import, make sure you grab the category and tag id
    add_action( 'smart_seo_import_update', 'demo_update_categories_tags', 10, 3 );
    function demo_update_categories_tags($post_id, $data, $headings){

    // check if `categories` column is present on CSV
    // check if `categories` column is present on CSV. Value should be integer
    if( isset( $data['categories'] ) && !empty($data['categories']) ){
    wp_set_object_terms($post_id, $data['categories'], 'category');
    }

    // check if `tags` column is present on CSV
    // check if `tags` column is present on CSV. Value should be integer
    if( isset( $data['tags'] ) && !empty($data['tags']) ){
    wp_set_object_terms($post_id, $data['tags'], 'post_tag');
    }
  2. freddielore revised this gist Mar 14, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions smart-seo-tags-categories.php
    Original file line number Diff line number Diff line change
    @@ -29,12 +29,12 @@ function demo_update_categories_tags($post_id, $data, $headings){

    // check if `categories` column is present on CSV
    if( isset( $data['categories'] ) && !empty($data['categories']) ){
    wp_set_post_terms($post_id, $data['categories'], 'category');
    wp_set_object_terms($post_id, $data['categories'], 'category');
    }

    // check if `tags` column is present on CSV
    if( isset( $data['tags'] ) && !empty($data['tags']) ){
    wp_set_post_terms($post_id, $data['tags'], 'post_tag');
    wp_set_object_terms($post_id, $data['tags'], 'post_tag');
    }

    }
  3. freddielore revised this gist Mar 14, 2022. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions smart-seo-tags-categories.php
    Original file line number Diff line number Diff line change
    @@ -22,4 +22,21 @@ function child_theme_callback_tags( $post ){
    }
    return '';
    }

    // also process `categories` and `tags` columns during CSV import
    add_action( 'smart_seo_import_update', 'demo_update_categories_tags', 10, 3 );
    function demo_update_categories_tags($post_id, $data, $headings){

    // check if `categories` column is present on CSV
    if( isset( $data['categories'] ) && !empty($data['categories']) ){
    wp_set_post_terms($post_id, $data['categories'], 'category');
    }

    // check if `tags` column is present on CSV
    if( isset( $data['tags'] ) && !empty($data['tags']) ){
    wp_set_post_terms($post_id, $data['tags'], 'post_tag');
    }

    }

    ?>
  4. freddielore created this gist Jul 8, 2020.
    25 changes: 25 additions & 0 deletions smart-seo-tags-categories.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    <?php
    // add this to your theme's functions.php or ask your developer to append the following lines
    add_filter( 'smart_seo_export_fields', 'child_theme_export_tags_categories', 8, 1 );
    function child_theme_export_tags_categories( $fields ){

    $fields[] = array( 'categories', 'child_theme_callback_categories' );
    $fields[] = array( 'tags', 'child_theme_callback_tags' );

    return $fields;
    }

    function child_theme_callback_categories( $post ){
    if( $post->post_type == 'post' ){
    return strip_tags( get_the_category_list( ', ', '', $post->ID ) );
    }
    return '';
    }

    function child_theme_callback_tags( $post ){
    if( $post->post_type == 'post' ){
    return strip_tags( get_the_tag_list( '', ', ', '', $post->ID ) );
    }
    return '';
    }
    ?>