PHP code example of marshallu / mu-seo

1. Go to this page and download the library: Download marshallu/mu-seo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marshallu / mu-seo example snippets


add_filter( 'mu_seo_post_types', function( $post_types ) {
    $post_types[] = 'faculty';
    $post_types[] = 'program';
    return $post_types;
} );

add_filter( 'mu_seo_post_types', function( $post_types ) {
    return array_diff( $post_types, array( 'attachment' ) );
} );

add_filter( 'mu_seo_og_image_id', function( $image_id, $post_id ) {
    if ( $image_id || ! is_singular( 'mu_profile' ) ) {
        return $image_id;
    }
    $headshot = get_field( 'profile_headshot', $post_id );
    return $headshot ? absint( $headshot ) : $image_id;
}, 10, 2 );

add_filter( 'mu_seo_og_type', function( $type, $post_id ) {
    if ( is_singular( 'mu_profile' ) ) {
        return 'profile';
    }
    return $type;
}, 10, 2 );

add_filter( 'mu_seo_schema', function( $schema, $post_id, $post_type ) {
    if ( 'event' !== $post_type ) {
        return $schema;
    }

    return array(
        '@context'  => 'https://schema.org',
        '@type'     => 'Event',
        'name'      => get_the_title( $post_id ),
        'startDate' => get_field( 'event_start_date', $post_id ),
        'location'  => array(
            '@type' => 'Place',
            'name'  => get_field( 'event_location', $post_id ),
        ),
    );
}, 10, 3 );

add_filter( 'mu_seo_schema', function( $schema, $post_id, $post_type ) {
    if ( ! empty( $schema ) && 'post' === $post_type ) {
        $schema['articleSection'] = get_field( 'category_label', $post_id );
    }
    return $schema;
}, 10, 3 );

add_filter( 'mu_seo_schema', function( $schema, $post_id, $post_type ) {
    return 42 === $post_id ? array() : $schema;
}, 10, 3 );

wp-content/
└── plugins/
    └── herd-seo/
        ├── mu-seo.php
        └── 
json
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "...",
  "description": "...",
  "url": "...",
  "datePublished": "2024-01-01T00:00:00+00:00",
  "dateModified": "2024-01-01T00:00:00+00:00",
  "author": { "@type": "Person", "name": "..." },
  "publisher": { "@type": "Organization", "name": "..." },
  "image": { "@type": "ImageObject", "url": "...", "width": 1200, "height": 630 }
}
json
{
  "@context": "https://schema.org",
  "@type": "WebPage",
  "name": "...",
  "description": "...",
  "url": "...",
  "datePublished": "2024-01-01T00:00:00+00:00",
  "dateModified": "2024-01-01T00:00:00+00:00",
  "publisher": { "@type": "Organization", "name": "..." },
  "primaryImageOfPage": { "@type": "ImageObject", "url": "...", "width": 1200, "height": 630 }
}