• Resolved MTWK-IDG

    (@mtwk-idg)


    I’m attempting to overwrite the open protocol og:description with the current yoast meta using the filter open_graph_protocol_meta. I keep getting an error message. Could you please advise on the correct usage of the filter please.

    Here’s my current code:

    ‘function override_description_OGP($content,og:description) {
    $ai_yoast_description = get_post_meta( get_the_ID(),’_yoast_wpseo_metadesc’ );
    $content = $ai_yoast_description[0];
    return $content;
    }
    add_action(‘open_graph_protocol_meta’, ‘override_description_OGP’);’

    Getting the following error:
    Parse error: syntax error, unexpected ‘:’, expecting ‘&’ or T_VARIABLE in /nas/wp/www/staging/newfifteen40/wp-content/themes/new-Divi-chlid/functions.php on line 47
    This is referencing the function override_description_OGP($content,og:description) {
    section of the code.

    I’ve also tried putting og:description as a string ‘og:description’ in the parameters. This didn’t work either.

    https://www.ads-software.com/plugins/open-graph-protocol-framework/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author itthinx

    (@itthinx)

    Hey,

    You are using an invalid syntax in your function signature:

    function override_description_OGP($content,og:description) { ...

    is not valid PHP code.

    The error message points you to the fact that og:description is not a valid function parameter declaration. You should review https://php.net/manual/en/functions.user-defined.php to understand how to write a function properly.

    I hope that helps you to get started ??

    Cheers

    Thread Starter MTWK-IDG

    (@mtwk-idg)

    The following code applies the new content to ALL open graph data. How do I just change the og:description

    function replace_meta_description($content,$property='og:description')
    {
    
    	$ai_yoast_description = get_post_meta( get_the_ID(),'_yoast_wpseo_metadesc' );
    	$yoast_description = $ai_yoast_description[0];
    	$content = $yoast_description;
    
    	return $content;
    }
    add_filter('open_graph_protocol_meta','replace_meta_description');

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Overwrite content of description meta with yoast’ is closed to new replies.