wornways
Forum Replies Created
-
Forum: Plugins
In reply to: [Open Graph and Twitter Card Tags] fb_og_title filterI 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 dataIn 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
}Forum: Plugins
In reply to: [Open Graph and Twitter Card Tags] fb_og_title filterI 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?