WordPress.org

Forums

All in One SEO Pack
Using excerpt in og:description (11 posts)

  1. MDS
    Member
    Posted 1 year ago #

    is it possible to use excerpt in og:description? i tried other plugins that works but i removed it due to duplicated og generated.

    http://wordpress.org/plugins/all-in-one-seo-pack/

  2. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    Hi MDS,

    You'd do it like this:

    add_filter( 'aiosp_opengraph_meta', 'mds_filter_description' );
    
    function mds_filter_description( $value, $type, $field ) {
        if ( $field == 'description' ) {
            global $post;
            if ( !empty( $post ) ) $excerpt = $post->post_excerpt;
            if ( !empty( $excerpt ) ) $value = $excerpt;
        }
        return $value;
    }
  3. MDS
    Member
    Posted 1 year ago #

    thanks but which file should i put this code to?

  4. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    Hi MDS,

    You may put that code in the functions.php file in your theme, or in a plugin.

  5. MDS
    Member
    Posted 1 year ago #

    it's not working, whenever i put them in theme's functions.php or in a plugin, it has below error:

    Warning: Missing argument 2 for mds_filter_description() in /home3/xxx/public_html/wp-content/plugins/all-in-one-seo-pack/aioseop_functions.php on line 617

  6. MDS
    Member
    Posted 1 year ago #

    as i enabled your Social Meta feature, and whatever i put in the description field in the Social Settings tab (under each post) seems to be ignored, not working at all, will it be fixed in the next version?

  7. nandastone
    Member
    Posted 1 year ago #

    Hi Peter,

    I'm experiencing the same issue as MDS. Line 484 of aioseop_opengraph.php:

    $filtered_value = apply_filters( $this->prefix . 'meta', $filtered_value, $t, $k );

    $t and $k are not being passed to filter hooks. func_get_args() reports:

    array(1) {
      [0]=>
      string(70) "Pet minding while you shop this Easter | Indooroopilly Shopping Centre"
    }

    Just the value of the filter, no extra parameters.

  8. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    Hi nandastone,

    In the WordPress Plugin API, you have to specify how many arguments you want, so change the add_filter() line like so:

    add_filter( 'aiosp_opengraph_meta', 'mds_filter_description', 10, 3 );

    The 10 is the default priority of the hook; the 3 is the number of arguments passed.

  9. nandastone
    Member
    Posted 1 year ago #

    Thanks Peter, that's some handy information, and has solved my problem. Coming from JS, that's a pretty bizarre requirement.

  10. Peter Baylies
    Member
    Plugin Author

    Posted 1 year ago #

    It's admittedly a bit quirky, the Plugin API dates from pre-1.0 versions of WordPress (and that feature from WordPress 1.5.1); but that's the way it works, and you likely will get used to it eventually...

  11. nandastone
    Member
    Posted 1 year ago #

    Thanks again :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • All in One SEO Pack
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.