Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure content in description field for each post #85

Closed
jserrao opened this issue Feb 2, 2017 · 12 comments
Milestone

Comments

@jserrao
Copy link

@jserrao jserrao commented Feb 2, 2017

I'm wondering how SEO Framework gets this data and is there a way to change it? It always says the descriptions are bad but wondering if there is a way to change the defaults without forking the project.

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Feb 3, 2017

Hi @jserrao,

TSF gets the fallback description data for singulars and terms from method the_seo_framework()->fetch_excerpt(), called by the_seo_framework()->get_excerpt_by_id().
... which is called by the_seo_framework()->generate_excerpt().

I'm not sure why it always says bad, but I guess you're using a page builder? Page Builders internally prevent the $post->post_content from returning anything; because it ought to be full of shortcodes.

Either way, there currently is no overwrite filter for descriptions or its extraction; I never thought one needed to generate their own descriptions.
You can also manually fill in the custom description meta field, if needed.

If you require a filter, please inform me on when and where :) I'd be more than happy to expand the API.

Cheers!

@jserrao

This comment has been minimized.

Copy link
Author

@jserrao jserrao commented Feb 3, 2017

Ah, makes sense why this is pulling 'bad' descriptions on my site. I'm extensively using Advanced Custom Fields (ACF) and don't have a typical excerpt to pull, it's just getting a title and putting it into the description field now.

What I've done to fix this is kinda hacky - basically, I just generate my own description field in a WP template partial for the head, injecting after TSF to fix the problem:

    // Output missing descriptions from SEO framework plugin
    if (is_singular('departments') || is_singular('features') || is_singular('post')) {
      echo '<meta name="description" content="' . get_field('subtitle') .'">';
      echo '<meta name="twitter:description" content="' . get_field('subtitle') . '">';
      echo '<meta property="og:description" content="' . get_field('subtitle') . '">';
    }

Ideally, I'd like to be able to redirect the default description field in TSF to a custom ACF field I've made (subtitle in my case) with a filter.

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Feb 4, 2017

Hi @jserrao,

Just be careful it doesn't output duplicated tags, as Search Engines and Social Sites alike tend to take the first entry and might see this as an erroneous output.

I'll see what I can do with a filter in order to short-circuit the output. That would be in 2.9.0-dev1.
Tomorrow I'll commit. Cheers!

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Feb 5, 2017

Hi @jserrao,

I forgot there already was a short-circuit filter, but that will only adjust the actual output of the page, not all things that relate to it.

For this, the following filter should be used:

add_filter( 'the_seo_framework_description_output', function( $description = '', $post_or_term_id = 0 ) {

	// code here
	
	return $description;
}, 10, 2 );

The short-circuit filters that affects all (SEO Bar, placeholder fields, counters, etc.) are still on their way.

Cheers!

@jserrao

This comment has been minimized.

Copy link
Author

@jserrao jserrao commented Feb 10, 2017

Thanks, great plugin btw.

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Feb 10, 2017

Thanks!

Also, my excuses for not implementing the new filter already — I've been feeling under the weather as of last week. Nevertheless, I'll ping this issue when it's implemented. 😄

@sybrew sybrew closed this in 593bb9c Mar 1, 2017
@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Mar 1, 2017

The filters:

  1. the_seo_framework_custom_field_description
  2. the_seo_framework_generated_description
  3. the_seo_framework_fetched_description_excerpt

Commit: 593bb9c

Enjoy!

@dvrcthewrld

This comment has been minimized.

Copy link

@dvrcthewrld dvrcthewrld commented Mar 15, 2017

When this is released, we'll be able to use one of these filters to set a default og:description that will be used when no other description exists?

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Mar 16, 2017

Hi @dvrcthewrld,

Yes, that's possible. Be aware that you should never use duplicated descriptions.
Each page must have a unique description.

the_seo_framework_custom_field_description and the_seo_framework_custom_field_description work like so:

add_filter( 'the_seo_framework_custom_field_description', function( $description, $args ) {
    if ( ! $description ) {
        // Code here....
        $description = 'My custom description';
    }

    return $description;
}, 10, 2 );
@jserrao

This comment has been minimized.

Copy link
Author

@jserrao jserrao commented Aug 23, 2017

@sybrew - just wanted to add that these filters work very well. I've been able to customize descriptions on a couple of sites now with durable results. Thanks so much for this addition.

@edflips

This comment has been minimized.

Copy link

@edflips edflips commented Jun 26, 2018

Hi, I have a similar problem, as I extensively use ACF and don't use the_content() field on my custom post types at all, which leads to the SEO Framework description reporting as bad.

screen shot 2018-06-26 at 15 06 47
screen shot 2018-06-26 at 15 07 00

How would I go about using the above filters to replace my descriptions? I also thought about using an ACF save hook to duplicate content into the main content area, but would prefer not to keep 2x the description field in the database if i can avoid it.

Many thanks!

@sybrew

This comment has been minimized.

Copy link
Owner

@sybrew sybrew commented Jun 26, 2018

Hi @PUncle

The new filters were described earlier in this issue, and you should use: the_seo_framework_fetched_description_excerpt.

e.g.:

add_filter( 'the_seo_framework_fetched_description_excerpt', function( $excerpt, $page_id ) {
	$field = function_exists( 'get_field' ) ? get_field( 'my-field', $page_id ) : '';
	return $field ?: $excerpt;
}, 10, 2 );

Regardless, I recommend using custom descriptions that fit Google's guidelines.

As the enhancement has been made a year ago--I'm locking this issue.
If you require further support, please open a new issue.

P.S. it looks like you're using Internet Explorer. I'm dropping support for that in the next major release. I urge moving to Edge or a Blink-based browser.

Repository owner locked as resolved and limited conversation to collaborators Jun 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.