Here’s how I fixed it. If you paste this code in your theme’s functions.php, it will use the image set for Facebook also for Twitter if no image is set for Twitter.
If there is not image set for both Facebook and Twitter, it falls back to the default Facebook image in the Yoast settings (unfortunately, you can’t provide a default Twitter image there, so we’ll be using the Facebook one).
// Add Twitter image to every page /article if none is defined
add_filter('wpseo_twitter_image', 'change_twitter_image');
function change_twitter_image($image) {
if (!$image) {
global $post;
if (!$image = get_post_meta($post->ID)["_yoast_wpseo_opengraph-image"][0]) {
$image = get_option("wpseo_social")["og_default_image"];
}
}
return $image;
};
Related Posts:
- Generating rel=prev and rel=next only on wordpress categories
- Adding multiple taxonomy filters to functions.php
- remove empty paragraphs from the_content?
- Issues with title-tag and document_title_parts
- Add tags to the section via functions.php
- Set JPEG compression for specific custom image sizes
- Define custom Page Template without its own .php file
- How to reduce original image quality on upload?
- syntax for remove_filter in parent theme with class
- Add body class of category parent
- Is checking whether the blog is installed necessary?
- Convert hyphen to underscore in permalinks
- Override parent theme function that is not hooked or in the functions.php file
- Programmatically Add Font-Awesome Icons to Category Widget
- Remove bulk actions based on user role or capabilities
- How to override filter in child theme?
- Removing title from page
- Hide some items from Screen options in dashboard for products
- How to change a certain text or term of WordPress into a custom into the whole site?
- Adding body class when post contains a specific shortcode
- Replace Archive Widget Link Text
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Best way to programatically add “rel” attributes to page and post images
- Limit filter upgrader_post_install to a single plugin
- How to update feed only 2-3 times a week (for Feedburner email)?
- Manipulate Output of wp_list_something: select menu instead of li’s
- Gravity Forms field entries into wp_query loop [closed]
- Show excerpt for only first post in query
- Remove function or filter
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Adding HTML to the end of every post with the Block Editor
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Pulling Twitter RSS feed not working as expected (fatal error)
- Passing values from a widget to a function within a plugin
- Publish/Update post is changing image links from file url to post url
- Replace a menu with widget or a custom template file programmatically
- woocommerce change currency per category [closed]
- Run wp_kses_decode_entities on atom feed?
- Filtering out the #more anchor link that gets produced by
- Can’t filter wp_get_attachment_link
- append to existing parent theme function
- Override the WordPress core function wp_referer_field
- Modify post filter to set custom number of posts per page and exclude child posts
- How can I add a filter for specific categories on functions.php?
- How to add custom JavaScript in functions?
- How to edit the Tags within the image file URLs?
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Add_filter when value is no variable?
- How to add_filter html template to middle of content
- Redefine function arguments before rendering
- How to edit classes in body tag?
- Possible to hook into Media Library preview File column and use a custom image?
- Combine embed_oembed_html and oembed_result
- login_headertitle is deprecated since version 5.2.0
- Programmatically add Yoast meta description after post save
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Filter to wp_list_authors
- Native gallery custom html output
- The_content and Preg_replace in loaded Iframe [closed]
- How to edit/replace Parent functions.php function in Child Theme to add “Walker” class
- Functions Filter Question [closed]
- Add Adsense code between job listings – wp job manager plugin
- Replace header image on all other pages but home – URL issue
- Changing the text of Upload/Insert on Posts and Pages Screen
- Any adverse effects of adding apply_filters to a function?
- Workaround for og:image unsupported webp image type, Yoast SEO?
- how can I add filter in specfic field in my website?
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Customizing the wp_video_shortcode output with add_filter
- How to add HTML into error message
- Removing comment lines from all enqueued js files using a filter function
- post value to function with Ajax and jQuery
- How Do I Unhook This Parent Theme Function?
- Allow user only create specific tags
- Child theme remove parent filter in functions
- function replace_text for entire page
- add product thumbnail to checkout page only and include variation name
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- Graphic before title – Specific Category
- Which method is more correct for removing WooCommerce Extensions menu item?
- Hide disclaimer from summary excerpts
- Only seems to be displaying one child when there are supposed to be multiple
- Best way to add image to recent posts widget?
- Why might wptexturize have become re-enabled?
- Shortcode to eliminate and replace with
- previous_post_link inside of a function?
- Search and Replace Script Loader in Head Only Works in Footer
- functions.php filters not applied in AJAX call
- Problem in outputting shortcode
- Settings in functions.php used by a plugin
- How to Add A Rel Filter to All Links?
- Allow tags and attributes in post and pages content
- Override parent theme function that is not hooked or in the functions.php file
- child_of not working while searching
- Can’t change excerpt length and more tag
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Filter to strip unnecessary attributes
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- function to show youtube videos within excerpt – if condition and apply_filters
- How can I modify or filter this variable in an existing class? (Mai Theme)