Access all of Typerocket. Get Pro.
SEO Extension
( v5 )
- # SEO Extension
- # SEO Meta Box
- # SEO Fields For Custom Resource
- # SEO Hooks
- # typerocket_seo_post_types
- # typerocket_seo_fields
- # typerocket_seo_meta
- # typerocket_view_document_title
SEO Extension
To begin, be sure your theme has title tag support enabled.
add_theme_support( 'title-tag' );
If you want to disabled the SEO extension, you can remove it from the extensions list or add the following to your wp-config.php
.
define('TYPEROCKET_SEO', false);
If Yoast SEO or All in One SEO Pack are installed the TypeRocket's SEO extension will get disabled automatically.
SEO Meta Box
The Seo
extension adds SEO meta boxes to all public post types by default. The meta box can be used to add:
- Basic metadata.
- Twitter cards.
- Open graph tags for Facebook or Pinterest.
- Robot meta and redirects.
The meta box also provides buttons for quickly analyzing your posts Schema data and Google Page Speed.
SEO Fields For Custom Resource
You can also add the SEO field to any custom resource you like using the tr_seo_meta_fields()
function. For the model used, you must save the SEO fields in a column named seo
in the database.
For example, your controller and views:
// ...
use \App\Models\Node;
class NodeController extends Controller
{
public function add() {
$form = tr_form(Node::class);
return tr_view('nodes.show', campact('form'));
}
public function create() {
// Do some node creation
}
public function show($id) {
$node = (new Node)->find($id);
$url = site_url('/nodes/' . $id);
return tr_view('nodes.show', campact('node'))->setSeoMeta($node->seo, $url);
}
}
<!-- View file: nodes.add -->
<?php echo tr_seo_meta_fields($form); ?>
<!-- View file: nodes.show -->
<?php var_dump($node); ?>
SEO Hooks
The SEO extension comes with several hooks.
- Action -
typerocket_seo_meta
- Used to output custom HTML meta tags. - Filter -
typerocket_seo_meta
- Used to filter the meta data used for meta tags. - Action -
typerocket_seo_fields
- Used to add custom fields to the general tab of the SEO meta box. - Filter -
typerocket_seo_post_types
- Used to control which post types have the SEO meta box. - Filter -
typerocket_seo_url
- Used to control the URL used for OG. - Filter -
typerocket_view_document_title
- Used to control the document title text.
typerocket_seo_post_types
If you want to control what post types the meta box is added too, you can use the typerocket_seo_post_types
filter hook. Only post types added will have the meta box added.
add_filter('typerocket_seo_post_types', function($types) {
return ['page', 'post'];
});
typerocket_seo_fields
If you want to add fields to the SEO metabox, use the typerocket_seo_fields
action hook.
add_action('typerocket_seo_fields', function($form) {
echo $form->text('basic.Keywords');
});
typerocket_seo_meta
If you want to add fields to the SEO metabox, you will also want to display them on each page. You can use the typerocket_seo_meta
action hook to output new meta.
add_action('typerocket_seo_meta', function($seo) {
$keywords = esc_attr($seo->meta['basic']['keywords'] ?? '')
echo "<meta name=\"keywords\" content"{$keywords}">";
});
typerocket_view_document_title
You can use the typerocket_view_document_title
to set a view's document title text. This can be helpful when an SEO plugin overrides the document title text, and you want to set the view's title.
add_filter('typerocket_view_document_title', function($title, $view) {
return $title
}, 10, 2);
Found a typo? Something is wrong in this documentation? Fork and edit it!