Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress SEMrush SEO Writing Assistant plugin with custom post types

This patch allows to add SEMrush SEO Writing Assistant metabox in Custom Post Types edit pages.

Applying patch

Go to the wp-content/plugins/semrush-seo-writing-assistant/ plugin directory and type:

patch -p 0 < /path/to/saved/semrush-seo-writing-assistant-1.0.3-CPT.patch

Adding SEMrush SEO Writing Assistant metabox to CPT

In order to add SEMrush SEO Writing Assistant metabox to my_cpt custom post type, add a filter like following in your plugins or functions.php file:

add_filter( 'semrush_seo_writing_assistant_post_types', function( $post_types ) {
	return array_merge( $post_types, array( 'my_cpt' ) );
} );
Index: admin/class-semrushswa-metabox.php
===================================================================
--- admin/class-semrushswa-metabox.php (revision 9548)
+++ admin/class-semrushswa-metabox.php (working copy)
@@ -47,11 +47,21 @@
SEMRUSH_SEO_WRITING_ASSISTANT_VERSION,
true
);
+
+ /**
+ * Filter post types array where to display this metabox.
+ *
+ * @param array $post_types. Default to `array( 'post', 'page', 'product' )`.
+ *
+ * @return array
+ */
+ $post_types = apply_filters( 'semrush_seo_writing_assistant_post_types', array( 'post', 'page', 'product' ) );
+
add_meta_box(
'swa-meta-box',
__( 'SEMrush SEO Writing Assistant' ),
array( $this, 'render_metabox' ),
- array( 'post', 'page', 'product' ),
+ $post_types,
'advanced',
'default',
array(
Index: semrush-seo-writing-assistant.php
===================================================================
--- semrush-seo-writing-assistant.php (revision 9547)
+++ semrush-seo-writing-assistant.php (working copy)
@@ -31,7 +31,7 @@
/**
* Current plugin version.
*/
-define( 'SEMRUSH_SEO_WRITING_ASSISTANT_VERSION', '1.0.3' );
+define( 'SEMRUSH_SEO_WRITING_ASSISTANT_VERSION', '1.0.4' );
/**
* Begins execution of the plugin.
@@ -39,7 +39,7 @@
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
- *
+ *
* @since 1.0.0
*/
function run_semrush_swa() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment