Support » Plugins and Hacks » Using excerpt in og:description

Using excerpt in og:description

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Peter Baylies


    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;

    thanks but which file should i put this code to?

    Plugin Contributor Peter Baylies


    Hi MDS,

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

    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

    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?

    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) {
      string(70) "Pet minding while you shop this Easter | Indooroopilly Shopping Centre"

    Just the value of the filter, no extra parameters.

    Plugin Contributor Peter Baylies


    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.

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

    Plugin Contributor Peter Baylies


    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…

    Thanks again 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Using excerpt in og:description’ is closed to new replies.