Skip to content

Instantly share code, notes, and snippets.

@freddielore
freddielore / woocommerce-gtin-export.php
Created March 13, 2022 02:42
Export WooCommerce GTIN/ISBN/MPN info to CSV for bulk editing
<?php
/** Originally from https://labs.freddielore.com/how-to-export-yoast-woocommerce-gtin-data-to-csv-for-bulk-import/
*/
// add `gtin8`, `gtin12`, `gtin13`, `gtin14`, `isbn`, `mpn` columns in CSV export
add_filter( 'smart_seo_export_fields', 'demo_export_yoast_gtin_data', 8, 1 );
function demo_export_yoast_gtin_data( $fields ){
$fields[] = array( 'gtin8', 'demo_get_gtin8' );
$fields[] = array( 'gtin12', 'demo_get_gtin12' );
@freddielore
freddielore / smart_seo_import_update.php
Last active November 7, 2022 06:03
Using wp_insert_post to create posts in bulk via CSV import
<?php
add_action( 'smart_seo_import_update', '_child_theme_create_post_with_custom_fields', 10, 3 );
function _child_theme_create_post_with_custom_fields($post_id, $data, $columns){
if( $post_id == 0 || $post_id == '0' ){
$args = array( 'post_title' => $data['post_title'],
'post_status' => 'publish',
'post_type' => $data['post_type'] );
@freddielore
freddielore / smart-seo-featured-image-by-url.php
Created August 5, 2021 01:30
[smart-seo-featured-image] Using `smart_seo_export_fields` and `smart_seo_import_update` hooks to bulk update featured images by URL with duplicates detection #smartseo #wordpress #wp
@freddielore
freddielore / export-term-meta-data-csv.php
Created July 9, 2020 02:36
[Export Term Meta Data] Exports term meta data to CSV for bulk editing #smartseo #wordpress
<?php
add_filter( 'smart_seo_export_fields', 'theme_export_tax_custom_fields', 8, 1 );
function theme_export_tax_custom_fields( $fields ){
$fields[] = 'custom_field_name_1';
$fields[] = 'custom_field_name_2';
return $fields;
}
add_action( 'smart_seo_import_update', 'theme_update_more_tax_custom_fields', 10, 2 );
function theme_update_more_tax_custom_fields($term_id, $data){
@freddielore
freddielore / smart-seo-tags-categories.php
Last active March 14, 2022 02:59
[Export Tags and Categories] Adds "tags" and "categories" column to the export CSV file for Smart SEO CSV Import/Export tool #smarseo #php
<?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;
}
@freddielore
freddielore / yoast-faq.css
Last active March 23, 2022 16:53
[Yoast SEO FAQ] Add collapsible headers support to Yoast SEO FAQ schema
/* Accordion
------------------------------------------------------------ */
.schema-faq-question{
cursor: pointer;
}
.schema-faq-question:before{
width: 16px;
height: 20px;
display: inline-block;
@freddielore
freddielore / smart_seo_export_desc.php
Created August 18, 2019 08:18
[smart_seo_export_desc] smart_seo_export_desc usage demo #wordpress #wp #php #seo
<?php
add_filter( 'smart_seo_export_desc', 'demo_export_default_seo_desc', 8, 2 );
function demo_export_default_seo_desc( $desc, $post ){
// ensuring no shortcodes are being retrieved
return strip_shortcodes( $desc );
}
?>
@freddielore
freddielore / smart_seo_export_fields.php
Created August 18, 2019 06:07
[smart_seo_export_fields] smart_seo_export_fields filter with added callback #wordpress #wp #seo #php
<?php
// add this to your theme's functions.php or ask your developer to append the following lines
add_filter( 'smart_seo_export_fields', 'demo_export_other_custom_fields', 8, 1 );
function demo_export_other_custom_fields( $fields ){
// See if this is a WPML site and add columns "language_code", "parent_title" to CSV
if( class_exists( 'SitePress' ) ){
$fields[] = array( 'language_code', 'callback_language_code' );
$fields[] = array( 'parent_title', 'callback_parent_lang' );
}
@freddielore
freddielore / functions.php
Last active August 18, 2019 04:52
[smart_seo_export_title_v2] smart_seo_export_title usage example #wordpress #genesis #seo
<?php
add_filter( 'smart_seo_export_title', 'demo_export_default_seo_titles_v2', 8, 2 );
function demo_export_default_seo_titles_v2( $title, $post ){
// if no custom SEO title being defined, get global defaults for Yoast
if( class_exists('WPSEO_Option' ) && empty($title) ){
$settings = get_option( 'wpseo_titles' );
$replacer = new WPSEO_Replace_Vars();
$title = $replacer->replace( $settings['title-' . $post->post_type], $post );
}
@freddielore
freddielore / functions.php
Created August 18, 2019 04:36
[smart_seo_export_title] smart_seo_export_title filter demo #wordpress #wp #seo
add_filter( 'smart_seo_export_title', 'demo_export_default_seo_titles', 8, 2 );
function demo_export_default_seo_titles( $title, $post ){
// if no custom SEO title being defined, get global defaults for Yoast
if( class_exists('WPSEO_Option' ) && empty($title) ){
$settings = get_option( 'wpseo_titles' );
$title = $settings['title-' . $post->post_type];
}