Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active September 9, 2026 11:11
Show Gist options
  • Select an option

  • Save igorbenic/eb97eb252a72c81b0f463b49ec5d1539 to your computer and use it in GitHub Desktop.

Select an option

Save igorbenic/eb97eb252a72c81b0f463b49ec5d1539 to your computer and use it in GitHub Desktop.
How to Programmatically Change Yoast SEO Open Graph Meta | http://www.ibenic.com/programmatically-change-yoast-seo-open-graph-meta
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_desc', 'change_desc' );
}
function change_desc( $desc ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
$desc = __( 'The best eBook you can have on your laptop, tablet or smartphone. See what others are reading to improve their career.', 'change_textdomain');
}
return $desc;
}
<?php
add_action( 'wpseo_opengraph', 'change_yoast_seo_og_meta' );
/**
* Function to add hooks and filter out the Yoast SEO Open Graph Meta Tags
*/
function change_yoast_seo_og_meta() {
// We will add the code here to change the meta tags
}
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_image', 'change_image' );
}
function change_image( $image ) {
if( $image == 'http://url_for_image_to_change' ) {
$image = 'http://url_to_our_new_image';
}
return $image;
}
<?php
function change_yoast_seo_og_meta() {
add_action( 'wpseo_add_opengraph_images', 'add_images' );
}
function add_images( $object ) {
$image = 'http://url_to_our_image.png';
$object->add_image( $image );
}
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_locale', 'change_locale' );
}
function change_locale( $locale ) {
// Article with the ID 123 is Croatian
// Other Articles are on English (or any site setting)
if( is_singular( 123 ) ) {
$locale = 'hr_HR';
}
return $locale;
}
<?php
// Code from Yoast SEO Plugin
public function og_tag( $property, $content ) {
$og_property = str_replace( ':', '_', $property );
/**
* Filter: 'wpseo_og_' . $og_property - Allow developers to change the content of specific OG meta tags.
*
* @api string $content The content of the property
*/
$content = apply_filters( 'wpseo_og_' . $og_property, $content );
if ( empty( $content ) ) {
return false;
}
echo '<meta property="', esc_attr( $property ), '" content="', esc_attr( $content ), '" />', "\n";
return true;
}
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_title', 'change_title' );
}
function change_title( $title ) {
// Landing Page eBook
if( is_singular( 123 ) ) {
$bought = get_bought_count_id( 123 );
// Change the title if it was already sold to more than 100
if( $bought > 100 ) {
$title = __( 'Get the eBook that was read by more than 100 people', 'change_textdomain' );
}
}
return $title;
}
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_type', 'change_type' );
}
function change_type( $type ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
$type = 'book';
}
return $type;
}
<?php
function change_yoast_seo_og_meta() {
add_filter( 'wpseo_opengraph_url', 'change_url' );
}
function change_url( $url ) {
// This article is actually a landing page for an eBook
if( is_singular( 123 ) ) {
$url = add_query_arg( 'from', 'facebook', $url );
}
return $url;
}
@broadstuart555-hue

Copy link
Copy Markdown

This is a helpful guide for developers who want more control over their website's Open Graph metadata. Proper social sharing optimization can make a big difference in how content is presented across platforms. The same attention to detail is valuable for sites like 3D printer, where well-optimized content and clear metadata help users discover useful 3D printing resources more easily.

@superdia11001-droid

Copy link
Copy Markdown

The future of financial services looks increasingly digital, and fintech is leading this transformation with continuous innovation and customer-focused solutions Fintech compliance software.

@superdia11001-droid

Copy link
Copy Markdown

Many professional cleaning companies in Dubai now offer environmentally friendly cleaning solutions that use non-toxic and biodegradable products. These services help reduce environmental impact while maintaining high cleaning standards. Eco-friendly cleaning is a great choice for families with children, pet owners, and businesses looking to promote sustainable practices without compromising cleanliness New Omniyat.

@superdia11001-droid

Copy link
Copy Markdown

"I had a great experience with Edinburgh Chauffeur Transfers. The driver arrived on time, the vehicle was spotless, and the journey was smooth from start to finish. It made traveling around Edinburgh much more comfortable and stress-free. I would definitely use their service again. https://chauffeurserviceedinburgh.co.uk/services/"

@lillysss22

lillysss22 commented Aug 1, 2026

Copy link
Copy Markdown

RadBoard is a dedicated employment platform that helps radiology professionals connect with trusted healthcare employers nationwide. It showcases a variety of opportunities, including remote radiology jobs, giving physicians greater flexibility in choosing roles that suit their experience and preferred work environment. RadBoard streamlines the career search with specialized listings created exclusively for the radiology community.

@superdia11001-droid

Copy link
Copy Markdown

I had a great experience with Affordable Chauffeur Edinburgh. The driver arrived on time, the vehicle was spotless, and the entire journey was comfortable and stress-free. I would definitely use their service again Corporate chauffeur Edinburgh.

@lillysss22

Copy link
Copy Markdown

Thanks for sharing.

@juliaaaa1534-coder

Copy link
Copy Markdown

Mobile gaming can offer quick, challenging experiences for players who enjoy testing timing, reflexes, and coordination. Geometry APK gaming is worth exploring for those interested in Geometry Dash and its mobile gameplay.

@OliverNoah22

OliverNoah22 commented Aug 23, 2026

Copy link
Copy Markdown

Programmatically changing Yoast SEO Open Graph meta can be handled using WordPress filters to customize social sharing data dynamically. 1pppp keeps the interface clean and clutter-free, letting players jump straight into Teen Patti or Rummy tables without extra steps. Visit now https://1pppapk.com.pk/.

@jacobtyler1592-byte

Copy link
Copy Markdown

This is a useful and well-organized gist. The practical approach makes the information easy to follow, especially for someone looking to understand the implementation rather than just the theory. Thanks for sharing!
https://pinvideoindirici.com.tr/

@damonlucas

Copy link
Copy Markdown

A useful topic for WordPress developers, especially when you need more control over how pages appear when shared on social media.
Completing a J188 download unlocks card games, slots, and fish games from a single home screen. New accounts typically register using a phone number and OTP verification.https://j188.net/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment