• I am using WordPress 4.7.3 running Sydney theme.

    I see this on your Facebook Open Graph, Google+ and Twitter Card Tags (2.0.8.1) WordPress Plug-In:

    Include Post/Page Title:
    <meta property=”og:title” content=”…”/>
    – You can change this value using the fb_og_title filter

    But can’t find any explanation anywhere of how to use fb_og_title filter, can you please let me know?

Viewing 5 replies - 1 through 5 (of 5 total)
  • You can use it in functions.php – just hook into it and echo whatever you want to replace the OG tag with.

    function my_new_title(){
    echo '<meta property="og:title" content="Whatever you want to replace it with">';
    }
    
    add_filter('fb_og_title', 'my_new_title');

    Thanks for this – but how strange to have a plugin where there’s no way to configure this value!

    I also saw this and wondered how to make it work. However, what you’re proposing here doesn’t make it possible to set og:title to what I want it to be for each post and page. There are three things we should be able to customize as we add or update a post or page:

    og:image (check)
    og:description (check)
    og:title ()

    The rest can be automatically generated and we’ll all be fine with it. I’m looking at editing the plugin now to see if I can figure out how to add a edit box for the title. I found the spot where the label and text area are created, but it looks really complicated to create my own field for the title. Should only take you guys about 5 minutes to add this and post an update.

    Whaddaya say?

    I added the option to edit the og:title in the posts. Works beautifully. Here’s my code:

    In class-webdados-fb-open-graph-admin.php I added the following in post_meta_box just before the description box code:

    <!– EAT — Begin attempt to add custom title edit field –>
    <?php
    // Get current title
    $value_title = get_post_meta($post->ID, ‘_EAT_fb_open_graph_specific_title’, true);
    ?>
    <p>

    <label for=”EAT_fb_open_graph_specific_title”>
    <?php _e(‘Use this title’, ‘wonderm00ns-simple-facebook-open-graph-tags’); ?>:
    </label>

    <br/>
    <?php
    if ( $webdados_fb->is_yoast_seo_active() && $this->options[‘fb_show_wpseoyoast’]==1 ) {
    _e(‘The Yoast SEO integration is active, so it\’s title will be used’, ‘wonderm00ns-simple-facebook-open-graph-tags’);
    } else {
    ?>
    <textarea id=”EAT_fb_open_graph_specific_title” name=”EAT_fb_open_graph_specific_title” style=”width: 100%;” rows=”1″><?php echo esc_textarea(trim($value_title)); ?></textarea>
    <br/>
    <?php
    _e(‘If this field is not filled, the title will be generated from the name you\’ve given your post or page’, ‘wonderm00ns-simple-facebook-open-graph-tags’);
    }
    ?>
    </p>
    <!– EAT — End attempt to add custom title edit field –>

    In the same file, I added the following to save_meta_boxes just after the description meta update code:

    // EAT begin attempt to add title data
    if ( isset($_POST[‘EAT_fb_open_graph_specific_title’]) ) {
    // Sanitize user input.
    if ( get_bloginfo(‘version’)>=’4.7.0′ ) { //sanitize_textarea_field only exists since 4.7.0
    $mydata = trim( sanitize_textarea_field( $_POST[‘EAT_fb_open_graph_specific_title’] ) );
    } else {
    //Just in case…
    $mydata = trim( sanitize_text_field( $_POST[‘EAT_fb_open_graph_specific_title’] ) );
    }
    // Update the meta field in the database.
    update_post_meta($post_id, ‘_EAT_fb_open_graph_specific_title’, $mydata);
    }
    // EAT End attempt to add title data

    In class-webdados-fb-open-graph-public.php I modified the //original code thus:

    //Look for custom meta title. Use it if it’s there. If not, use original code.
    if ( $fb_title = trim( get_post_meta($post->ID, ‘_EAT_fb_open_graph_specific_title’, true) ) ) {
    //From our metabox
    } else {
    // begin original code
    $fb_title = wp_strip_all_tags( stripslashes( $post->post_title ), true );
    //SubHeading
    if ( isset($this->options[‘fb_show_subheading’]) && intval($this->options[‘fb_show_subheading’])==1 && $webdados_fb->is_subheading_plugin_active() ) {
    if (isset($this->options[‘fb_subheading_position’]) && $this->options[‘fb_subheading_position’]==’before’ ) {
    $fb_title = trim( trim(get_the_subheading()).’ – ‘.trim($fb_title), ‘ -‘ );
    } else {
    $fb_title = trim( trim($fb_title).’ – ‘.trim(get_the_subheading()), ‘ -‘ );
    }
    }
    // end original code
    }

    PS: I’ve changed all occurrences of “EAT_fb_open_graph_specific_title” and “EAT_fb_open_graph_specific_title” to “webdados_fb_open_graph_specific_title” and “_webdados_fb_open_graph_specific_title” in anticipation of remaining compatible with your next update.

    The addition of this one feature makes all the difference.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘fb_og_title filter’ is closed to new replies.