Wordpress-seo: Filters wpseo_metadesc, wpseo_title don't work in admin metabox

Created on 12 Oct 2014  路  10Comments  路  Source: Yoast/wordpress-seo

In admin metabox this filters are not applied, so
Snippet Preview and SEO Title remains unaffecte.

And more - even if you hook into wpseo_snippet and try to display real data, this plugin replace it trough javascript.

text analysis

Most helpful comment

Is this going to be picked up at any point? Seems to a crucial feature to me (we can now show the correct custom meta info on the frontend; but to the CMS user (e.g. our clients) it is extremely confusing. Also, in the submit box in the admin sidebar a bad content score is displayed now by default.

All 10 comments

Thanks for reporting this issue.
Unfortunately we will need a bit more information to research this problem. Please follow these guidelines to improve your bug report.

Also, it may help us a lot if you can provide a backtrace of the error encountered. This gist will explain how to enable the backtrace in your website: https://gist.github.com/jrfnl/5925642

Thank you.

WP 4.0
WordPress SEO 1.6.3

No errors, notices or warnings in logs with enabled debug.

Steps to reproduce

class test {
    function __construct() {
        add_filter ( 'wpseo_metadesc', array ($this, 'wpseo_metadesc_filter') );
        add_filter( 'wpseo_title', array($this, 'wpseo_title_filter'), 100, 1 );
    }

    function wpseo_title_filter( $title ) {
        return "wpseo_title";
    }

    function  wpseo_metadesc_filter($metadesc, $post ) {
        return "wpseo_metadesc";
    }
}

When viewing post result is

<title>wpseo_title</title>
<meta name="description" content="wpseo_metadesc"/>

But in preview snipet when you edit post filters don't work.
wp-admin/post.php?post=XYZ&action=edit

And a i mentioned in first report evem i hook in wpseo_snippet and generate right preview plugin replace it via javascript.

Hello, I am having the exact problem as mentioned here using v3.0.6

@scamartist26 I think you are right. This bug was reintroduced with the 3.0 release since the snippet preview functionality has been completely renewed. We'll investigate to see if it's possible to fix this in short term.

Related to #709.

Is this going to be picked up at any point? Seems to a crucial feature to me (we can now show the correct custom meta info on the frontend; but to the CMS user (e.g. our clients) it is extremely confusing. Also, in the submit box in the admin sidebar a bad content score is displayed now by default.

Any updates on this issue?

@slimndap @jdevalk @tacoverdo sorry to bother you but we've been trying to get this issue fixed via Yoast Premium support (we payed specifically to be able to get in touch with you guys more directly and solve this issue), but they do not seem to have the technical know-how. The only reply I'm getting is that it's only supposed to work with the ACF yoast content analasys plugin, and unless I am misunderstanding what the filter in question is about, this is incorrect.

Can this please get looked into and be fixed? Right now we have to develop our own hooks that run on post_save to simply write the correct data into the database, a far from ideal solution.

I dived into this and come to the conclusion that we cannot provide a definite fix. I will however try to help you fix your integrations. I'll break the problem down for you as good as I can and explain what you need to do to fix this.

The issue.

To be clear. On the frontend these filters still work and have never stopped working. That means Google is in fact getting the correctly filtered title and metadescription. You can verify this by checking the source of your page. You will see that the <title> and <meta name="description"> fields show the correctly filtered output.

There are two issues since the big 3.0 update in november 2015 that we cannot completely fix:
1) we are not showing the filtered title and metadescription in the snippet preview
2) we are not using the filtered title and metadescription in our content analysis

Why can't we simply make this work for you?

The content analysis and snippet preview are both JavaScript based and performed on the client side. This is done so we can update them in semi-real-time and give you feedback as you write your content. If we were to use the filtered title and description, we would have to pass those through the server side, apply the filters there and send them back to the page to use them there. This would be very bad for performance and would make both the content analysis and the snippet preview terribly slow.

What have we done to help you fix the problem?

We chose to break support for the PHP filters in the snippet preview and content analysis, and we came up with an alternative API on the client side. The downside of this is that you need to filter title and description twice now, the upside is that the content analysis and snippet preview remain fast and reliable.

To filter the title and description on the client side, you need to write a piece of JavaScript and include it on the post-edit page. We've written documentation on how to integrate with our content analysis tool and snippet preview here: https://github.com/Yoast/YoastSEO.js/blob/develop/docs/Customization.md

Getting started example

Here's a basic boilerplate. Please don't forget to also check the documentation linked above.

(function(){ // Isolate script in function to avoid conflicts 
  ExamplePlugin = function() {
    YoastSEO.app.registerPlugin( 'examplePlugin', {status: 'ready'} );

    /**
     * @param modification  {string}    The name of the filter
     * @param callable      {function}  The callable
     * @param pluginName    {string}    The plugin that is registering the modification.
     * @param priority      {number}    (optional) Used to specify the order in which the callables
     *                      associated with a particular filter are called. Lower numbers
     *                      correspond with earlier execution.
     */
    YoastSEO.app.registerModification( 'data_page_title', this.modifyTitle, 'examplePlugin', 5 );
    YoastSEO.app.registerModification( 'data_meta_desc', this.modifyDescription, 'examplePlugin', 5 );
  }

  /**
   * Adds some text to the title...
   *
   * @param title The page title to modify
   */
  ExamplePlugin.prototype.modifyTitle = function( title ) {
    return title + ' some text to add';
  };

  /**
   * Adds some text to the description...
   *
   * @param title The metadescription to modify
   */
  ExamplePlugin.prototype.modifyDescription = function( description ) {
    return description + ' some text to add';
  };

  /** if Yoast SEO is already loaded, instantiate the plugin */
  if ( typeof YoastSEO !== 'undefined' && typeof YoastSEO.app !== 'undefined' ) {
    new ExamplePlugin();
  }
  /** Yoast SEO will trigger a ready event when initialized. Load the plugin right after. */
  else {
    jQuery( window ).on(
      'YoastSEO:ready',
      function() {
        new ExamplePlugin();
      }
    );
  }
}());

That's all I can do for you to help you fix the problem. If you need any more assistance in integrating with the JavaScript, please let me know.

@slimndap @jdevalk @tacoverdo @omarreiss

In this case we'd have to write our own JS logic to get the data from the ACF custom fields in question, rather then being able to use ACF's API to get the content we need and pass it through your existing filters. This is really a high-maintenance workaround rather then a fix as we'd have to update our JS logic each time we change our custom field setup, rather then using PHP logic to do both at the same time.

To be honest I do not feel like this is being treated as seriously as it should be, considering that both the level of customisation that Yoast claims to provide, and the snippet preview is are the main selling points for our clients and CMS users. So we expect these kind of features to work together.

Especially when you keep in mind that we are paying customers, I think this "solution" is really a no-go. Either don't allow to filter the output on the frontend, or make it work on both ends. Now you're creating expectations that are impossible to meet.

Was this page helpful?
0 / 5 - 0 ratings