Last active
January 6, 2024 09:42
-
-
Save sybrew/4ec3d783cbccf3980d91eadcf2344906 to your computer and use it in GitHub Desktop.
Adds The SEO Framework's Title and Description columns on the edit screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: The SEO Framework - Add custom columns | |
| * Plugin URI: https://theseoframework.com/ | |
| * Description: Adds The SEO Framework's Title and Description columns on the edit screen. | |
| * Version: 9001.42.1 | |
| * Author: Sybre Waaijer | |
| * Author URI: https://cyberwire.nl/ | |
| * License: GPLv3 | |
| */ | |
| add_action( | |
| 'the_seo_framework_after_admin_init', | |
| function() { | |
| // Load class inside function, so we can defer object inheritance within a single file. | |
| new class extends The_SEO_Framework\Admin\Lists\Table { | |
| private $column_name = 'tsf-c-custom-title'; | |
| public function add_column( $columns ) { | |
| return array_merge( | |
| $columns, | |
| [ $this->column_name => 'Meta Title' ] | |
| ); | |
| } | |
| public function output_column_contents_for_post( $column_name, $post_id ) { | |
| if ( $this->column_name !== $column_name ) return; | |
| echo esc_html( tsf()->get_title( [ 'id' => $post_id ] ) ); | |
| } | |
| public function output_column_contents_for_term( $string, $column_name, $term_id ) { | |
| if ( $this->column_name !== $column_name ) return; | |
| echo esc_html( tsf()->get_title( [ 'id' => $term_id, 'taxonomy' => $this->taxonomy ] ) ); | |
| } | |
| }; | |
| // Load class inside function, so we can defer object inheritance within a single file. | |
| new class extends The_SEO_Framework\Admin\Lists\Table { | |
| private $column_name = 'tsf-c-custom-description'; | |
| public function add_column( $columns ) { | |
| return array_merge( | |
| $columns, | |
| [ $this->column_name => 'Meta Description' ] | |
| ); | |
| } | |
| public function output_column_contents_for_post( $column_name, $post_id ) { | |
| if ( $this->column_name !== $column_name ) return; | |
| echo esc_html( tsf()->get_description( [ 'id' => $post_id ] ) ); | |
| } | |
| public function output_column_contents_for_term( $string, $column_name, $term_id ) { | |
| if ( $this->column_name !== $column_name ) return; | |
| // phpcs:ignore -- Output is escaped; $this->taxonomy is inherited. | |
| echo esc_html( tsf()->get_description( [ 'id' => $term_id, 'taxonomy' => $this->taxonomy ] ) ); | |
| } | |
| }; | |
| } | |
| ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now compatible with TSF v5.0+, although it uses the privately marked class
The_SEO_Framework\Admin\Lists\Table.