Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author George Notaras

    (@gnotaras)

    Hello,

    It is possible to filter the generated Opengraph metadata and change og:title as you wish. Here is some sample code (I’ve borrowed it from another example in another topic, but you get the idea):

    function customize_og_title( $metatags ) {
        $metatags_new = array();
        foreach ( $metatags as $metatag ) {
            if ( strpos($metatag, 'og:title') === false ) {
                $metatags_new[] = $metatag;
            } else {
                $metadata_new[] = '<meta property="og:title" content="MY CUSTOM OG TITLE" />';
            }
        }
        return $metatags_new;
    }
    add_filter( 'amt_opengraph_metadata_head', 'customize_og_title', 10, 1 );

    This code can be added in the functions.php file of your theme or in a separate plugin.

    Hope this helps,

    George

    Thread Starter jesperlundnielsen

    (@jesperlundnielsen)

    Great, thank you, George.

    Plugin Author George Notaras

    (@gnotaras)

    It should be simpler, like in the following:

    function customize_og_title( $metatags ) {
        $metatags['og:title'] = '<meta property="og:title" content="MY CUSTOM OG TITLE" />';
        return $metatags;
    }
    add_filter( 'amt_opengraph_metadata_head', 'customize_og_title', 10, 1 );

    But, I intend to add proper keys in a future 2.7.X release.

    little typo in example (var name in else)

    correct:

    function customize_og_title( $metatags ) {
        $metatags_new = array();
        foreach ( $metatags as $metatag ) {
            if ( strpos($metatag, 'og:title') === false ) {
                $metatags_new[] = $metatag;
            } else {
                $metatags_new[] = '<meta property="og:title" content="MY CUSTOM OG TITLE" />';
            }
        }
        return $metatags_new;
    }
    add_filter( 'amt_opengraph_metadata_head', 'customize_og_title', 10, 1 );

    Thank you George for this really good plugin!

    Plugin Author George Notaras

    (@gnotaras)

    @ole123123: Thanks for pointing that out and for posting the correct code snippet!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Changing the Open Graph title (og:title)’ is closed to new replies.