• Resolved JS Morisset

    (@jsmoriss)


    Hi!

    I’m the author of NGFB, WPSSO, and the WPSSO extensions. I recently added support for The SEO Framework to NGFB and WPSSO. I had some notes I wanted to share. 😉

    NGFB and WPSSO generate meta tags on the post/page/term/user pages using the ‘current_screen’ WP hook. The SEO Framework does not return a correct title / description value at this point unless I define the global $post variable. This is fine — I just thought you should know that The SEO Framework methods might be called a little earlier than you may have expected. 😉

    I noticed The SEO Framework includes some plugin compatibility checks. The following plugins create Open Graph and Twitter Card meta tags, along with JSON-LD markup on the home page (only) for WebSite, Person, and Organization:

    NextGEN Facebook (nextgen-facebook/nextgen-facebook.php)
    WordPress Social Sharing Optimization (wpsso/wpsso.php)

    The following plugin creates complete JSON-LD markup on all posts, pages, custom post types, etc.

    WPSSO Schema JSON-LD (wpsso-schema-json-ld/wpsso-schema-json-ld.php)

    js.

    https://wordpress.org/plugins/autodescription/

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    That’s awesome!

    I never thought they would be called that early (current_screen), but it does have support for this, but only if an ID is given.

    I’ll add a filter to the ID fetching, which should be called at plugins_loaded, priority 4 or higher (3, 2, 1, 0, -1, etc.).
    This filter, which is cached on the front-end, from 2.6.2, is:

    /**
     * Applies filters 'the_seo_framework_current_object_id' : integer
     * Can be either the Post ID, or the Term ID.
     *
     * @param int $id
     * @param bool Whether the globals WP_Query or current_screen are set.
     * @see AutoDescription_Query::can_cache_query()
     *
     * @since 2.6.2
     */
    $id = (int) apply_filters( 'the_seo_framework_current_object_id', $id, $this->can_cache_query() );

    In the future I’ll consider a taxonomy filter to be used throughout the plugin.

    The suggested plugins to detect have already been added to the “open_graph” detection since 2.6.1 :). I revised plugin detection in that update. I’ll see if I can add them to the “twitter_card” detection as well.

    Schema.org (in JSON+LD format) conflicts have yet to be tested in the Structured Data Testing tool. From my understanding, the first found is always used and shouldn’t cause conflicts. Some scripts, like the Breadcrumbs, allow for multiple to be used.

    For this reason, no LD+JSON detection has been integrated as of yet.

    I hope this clears things up, if you have any suggestions, comments or anything else, it will be greatly appreciated :)! Thanks!

    Have a wonderful day!

    Thread Starter JS Morisset

    (@jsmoriss)

    Hm. This may have more overhead for me — perhaps I could use both… For example, right now I’m using this:

    public function filter_title_seed( $title, $mod ) {
        $the_seo_framework = the_seo_framework();
        if ( is_admin() && $mod['is_post'] )
            SucomUtil::maybe_load_post( $mod['id'] );
        return $the_seo_framework->title();
    }

    I could also add a hook to ‘the_seo_framework_current_object_id’ and test for an empty $id, just in case. 😉 This would cover post, term, and user IDs?

    public function current_object_id( $id ) {
        if ( empty( $id ) ) {
            $lca = $this->p->cf['lca'];
            $use_post = apply_filters( $lca.'_header_use_post', false );
            $mod = $this->p->util->get_page_mod( $use_post );
            $id = $mod['id'];
        }
        return $id;
    }

    As for JSON-LD, the plugin defines the ‘mainEntityOfPage’ property, so that should prevent any conflicts, unless another Schema block also defines the ‘mainEntityOfPage’ property. 😉

    js.

    Thread Starter JS Morisset

    (@jsmoriss)

    BTW, this method ads a trailing slash, even on query args. 😉

    $the_seo_framework->the_url_from_cache()

    Example:

    http://example.com/2015/12/16/test/?abc=123/

    js.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    I have no idea what those code blocks should represent :^).
    But yes, the ID covers all IDs, as I believe it’s more reliable to check for “is_archive()“, “is_author()“, et cetera, rather than “is this the ID of?”.
    I haven’t gotten tot he “mainEntityOfPage” part yet, so I think we’re safe.

    The trailing slash is user defined through the permalinks settings.
    The query args shouldn’t come with it, unless you tell it to do so. I’m unsure of what composition it’s tested on so I can’t reliably give an answer to that. Most of the times, all query arguments are removed from that URL. Of course, something could’ve slipped my mind, and then that’s a bug :).

    I hope this clears things up! I’d love to hear back from you. Have a great day :).

    Thread Starter JS Morisset

    (@jsmoriss)

    Don’t forget that is_singular(), is_archive(), is_author(), etc. usually don’t work on the admin side. 😉 I’ve added the filter you suggested, passing it the ID of the post, term, or user as required (for whatever is the current WP object).

    If you customize the canonical URL for a post (for example) by adding a query argument, The SEO Framework will add a trailing slash, even though the custom canonical URL did not have one.

    js.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    They’ve never worked in the admin side :(. So I’ve made that to work :).
    As it’s GPLv3, feel free to use it! I’ll flag that specific file GPLv2+ in a future update, so it’s more broadly accepted to be used within the WordPress community.

    Thanks for the bug report, it’s very helpful :). I’ll look into it!

    If you have any more light to shed on improving this plugin, feel free to do so!

    Have a great day :).

    Thread Starter JS Morisset

    (@jsmoriss)

    Nice work. 😉

    BTW, I’ve disabled the “Output knowledge tags?” option, but I’m still getting the following JSON added to the home page. Is there any way to disable it?

    <script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"WebSite","name":"Surnia Ulula (Admin)","url":"http:\/\/adm.surniaulula.com\/"}</script>
    <script type="application/ld+json">{"@context":"http:\/\/schema.org","@type":"WebSite","url":"http:\/\/adm.surniaulula.com\/","name":"Surnia Ulula (Admin)","potentialAction":{"@type":"SearchAction","target":"http:\/\/adm.surniaulula.com\/?s={search_term_string}","query-input":"required name=search_term_string"}}</script>

    js.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    The master filter:

    add_filter( 'the_seo_framework_ldjson_scripts', '__return_empty_string' );

    And others:

    add_filter( 'the_seo_framework_json_sitename_output', '__return_false' );
    add_filter( 'the_seo_framework_json_search_output', '__return_false' );
    add_filter( 'the_seo_framework_json_breadcrumb_output', '__return_false' );

    I believe they’re quite self explanatory :). Enjoy!

    There’s no filter present for disabling the knowledge graph. You could however empty the following filter, but that would still cause some rendering. Luckily, that’s only once, for the Home Page, per week. Then its empty output is stored within a transient.

    add_filter( 'the_seo_framework_json_options', '__return_empty_array' );

    I’ll see if I can add a more convenient filter in 2.6.3 :).

    Cheers!

    Thanks JS Morisset and Sybre Waaijer.

    Thread Starter JS Morisset

    (@jsmoriss)

    @Sybre I have similar functions called is_post_page(), is_term_page(), and is_user_page() which I use to load the appropriate module for the current page etc. I was using $screen->id, but after looking at your code, realized $screen->base (which I didn’t even know about) is a lot more efficient. 😉

    I like your use of a static variable within your method to cache the value. 😉

    js.

    Thread Starter JS Morisset

    (@jsmoriss)

    BTW, in is_archive_admin() you have:

    if ( isset( $current_screen->base ) && ( 'edit-tags' === $current_screen->base || 'term' === $current_screen->base ) )

    I tend to agree that ‘edit-tags’ (which is a listing) is an “archive” page, but ‘term’? To me that’s a singular page since it shows a single term…

    You could also check for ‘edit’ (post/page list) and ‘users’ (user list). 😉

    js.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    I got a little confused when writing that, as when I started I believe it was still term. But then WordPress 4.5.0 beta came out with it being edit-tags. They both should be the same: an archive holder.

    If you dig deeper you’ll find a conditional for the WordPress versions, which I found to be a nuisance. Nevertheless, it works as intended :).

    The conditional is used for the plugin itself, so also in The SEO Bar, which evidently needs that conditional. Sometimes I need to “generalize” things, and then use more conditionals if really needed.

    From the top of my head, edit is already taken into account. And users is planned when I get to Author SEO :).

    Thread Starter JS Morisset

    (@jsmoriss)

    Lol. I’m glad you replied — I’d cleaned-up some code and forgot that ‘term’ was only since 4.5! Looks like I’ll have to support ‘edit-tags’ for a bit longer. :p

    Thanks,

    js.

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi js,

    In 2.6.5, for the Knowledge Graph and LD+Json overall output, the following two boolean filters will be available:

    add_filter( 'the_seo_framework_json_search_output', '__return_false' );
    add_filter( 'the_seo_framework_ldjson_plugin_detected', '__return_false' );

    Enjoy! 🙂

    Thread Starter JS Morisset

    (@jsmoriss)

    Right now I’m using:

    • the_seo_framework_current_object_id
    • the_seo_framework_ldjson_scripts (return empty string

    You’re suggesting I use this instead?

    • the_seo_framework_current_object_id
    • the_seo_framework_json_search_output (return false)
    • the_seo_framework_ldjson_plugin_detected (return true)

    Thanks! 🙂

    js.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Notes about compat with WPSSO and WPSSO JSON…’ is closed to new replies.