• I found not being able to customize the title unacceptable, so I’ve made some changes. I already shared this (an earlier version) in response to another post, but I thought I’d share the most recent version here using the “code” tag so it hopefully presents better.

    First, the big reason why I wanted to be able to customize this information per post. I didn’t just want the title of a post being used as the og:title. I also wanted some other information to show up. For instance, instead of just “Poem Title” (without the quotes), have “Poem Title” — poem by Author (This time the title is inside quotes).

    This is also important for other types of pages. It’s been frustrating that WP treats FB and SEO titles and descriptions the same. They’re just not even in the same ballpark. When your post shows up in a Google search, you really want to present an excerpt from the post. When it shows up at Facebook, you want a brief explanation of the post along with an invitation to come check it out.

    Toward this end, I’m using Yaost SEO specifically for managing search engine related descriptions, titles, and keywords while I’m using your app specifically for Social Networking (especially Facebook) related descriptions, titles, and images. Your plugin was a.l.m.o.s.t there. Just need to be able to customize the titles.

    Here’s the code I’ve added:

    In the file “class-webdados-fb-open-graph-admin.php” I’ve added this to the function “post_meta_box” just before the code managing the description text area:

    		<!-- EAT -- Begin attempt to add custom title edit field -->
    		<?php
    		// Get current title
    		$value_title = get_post_meta($post->ID, '_webdados_fb_open_graph_specific_title', true);
    		?>
    		<p>
    			<strong>
    				<label for="webdados_fb_open_graph_specific_title">
    					<?php _e('Use this title', 'wonderm00ns-simple-facebook-open-graph-tags'); ?>:
    				</label>
    			</strong>
    			<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 {
    				?>
    				<input type="text" id="webdados_fb_open_graph_specific_title" name="webdados_fb_open_graph_specific_title" value="<?php echo esc_attr( $value_title ); ?>" size="75"/>
    				<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’ve added the following to the function “save_meta_boxes” just after your code for processing the custom description inside the “if ($save) {” block:

    			// EAT begin attempt to add title data
    			if ( isset($_POST['webdados_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['webdados_fb_open_graph_specific_title'] ) );
    				} else {
    					//Just in case...
    					$mydata = trim( sanitize_text_field( $_POST['webdados_fb_open_graph_specific_title'] ) );
    				}
    				// Update the meta field in the database.
    				update_post_meta($post_id, '_webdados_fb_open_graph_specific_title', $mydata);
    			}
    			// EAT End attempt to add title data

    In the file “class-webdados-fb-open-graph-public.php” I’ve moved the “// begin/end original” code into the “else” end of an “if” statement as follows:

    						//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, '_webdados_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
    						}

    That’s it! It’s working fantastic. I’m going through all my posts now and using this new field to update the og:title as desired while at the same time further differentiating the SEO title to better optimize search engine results.

    Hope you’ll use this in your next update.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter wornways

    (@wornways)

    Sorry about the indentation. It’s using the indentation set at that particular point in the files.

    Thread Starter wornways

    (@wornways)

    Arrghhhh you killed my changes with your update. Now I have to put them back again. How do I prevent automatic update of a specific plugin? At least I have the code right here so I can just copy it back in.

    Thread Starter wornways

    (@wornways)

    Back in bid’ness. This is part of the reason why I shared the code I used to create custom titles with you. I wanted to be able to come back here and get it again if you did an update that didn’t include it. Please consider using the code. It works perfectly.

    If not, please at least tell me how to disable automatic updating of a specific plugin.

    Thread Starter wornways

    (@wornways)

    Solved the disable updates question. There’s a plugin called “Easy Updates Manager” that lets me disable updates for a specific plugin.

    Please respond to this post if you do an update that incorporates the ability to create custom og:titles as I’ve done. It’s also kind of important that you use the same “_webdados_fb_open_graph_specific_title” key if you do–which I’ve modeled after the key names already in use–so all my hard work won’t be undone.

    Thanks for this instruction. Works like a charm.
    This should be part of the PlugIn on next update.

    Thread Starter wornways

    (@wornways)

    This is really good to hear, George. Let me know when you publish the update and I’ll test it all out (since every single one of my posts uses a customized og:title that’s different from the SEO title) and report back to you.

    @wornways
    I think you got me wrong. I’m not the developer of the plugIn – I just find the mod usefull and was hoping that it is integrated in the next release ??

    Thanks anyway.

    Thread Starter wornways

    (@wornways)

    Ah I see. You used the code I posted to make your own changes. Be sure to install the Easy Updates Manager plugin so you can prevent the changes from being overwritten next time there’s an update. Hopefully the plugin developers will incorporate the changes and make us all very happy.

    Yes, I used your code for my own changes and installed the Extension you mentioned.

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Modified your plugin to allow me to change og:title in the post.’ is closed to new replies.