• Resolved Michael

    (@donohoe)


    My question applies to both the Meta Title and the Meta Description, however I’ll just use the Meta Title as an example.

    Currently, if I provide text for the Meta Title, then the Open Graph Title (and by default the Twitter Title) will also use that text.

    Is there a way to prevent this?

    The desired goal is that if I provide text for Meta Title it will use that. The Open Graph Title would not use that custom text (unless manually entered) and would continue to use the default text.

    I’ve looked for various filters but haven’t found anything that will help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hello!

    There is no way to prevent this unless you modify the (perceived) post metadata. But, when you fill in the post metadata with the “original” generated data, you’ll also need to read the post metadata. This creates an infinite loop.

    Below is the code I used to verify this. I commented out the lines that create an infinite loop, for somebody might blindly copy and paste this and crash their site…

    add_filter( 
    	'the_seo_framework_post_meta', 
    	function( $meta, $post_id ) {
    
    		if ( ! $meta['_open_graph_title'] ) {
    			// $meta['_open_graph_title'] = tsf()->get_generated_open_graph_title( [ 'id' => $post_id ] );
    		}
    			
    		if ( ! $meta['_open_graph_description'] ) {
    			// $meta['_open_graph_description'] = tsf()->get_generated_open_graph_description( [ 'id' => $post_id ] );
    		}
    		
    		return $meta;
    	},
    	10,
    	2
    );

    Perhaps you may find luck in lower-level filters (those from WordPress itself), but I always found metadata filters strenuous, to say the least — never in my support efforts have I been able to apply those.

    Thread Starter Michael

    (@donohoe)

    Thank you for looking into this. I think I found a way which hopefully avoids the infinite loop. This code refers to the Meta Title and OG/Twitter Title but I use same approach for Description fields:

    https://gist.github.com/donohoe/a6cfcf5e920e4e3ee29f2bedc1847a53

    There is still a separate problem on the frontend. While the PHP code appears to work, the placeholder attribute on the field INPUT and TEXTAREA elements still reflects the original behaviors.

    I am solving for that with this JS though I don’t like using setInterval this way or hard-coding ID names. I may modify it to only run if the plugin HTML is in-view

    https://gist.github.com/donohoe/393a795b764a4adefeaa5b8960c23908

    Plugin Author Sybre Waaijer

    (@cybr)

    Hi Michael,

    I’m glad you found a workaround, albeit a bit hacky. I replied to the gists, and I see you’ve already made some improvements.

    If you still require assistance, let me know!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adjust Title and Description default value behaviors’ is closed to new replies.