Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Last active May 2, 2026 17:00
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;
}
@sagive
Copy link
Copy Markdown

sagive commented Sep 16, 2019

Apologies - just a small question - why are there 2 functions for each filter? its a bit messy an unneeded i think ;)

Example for changing the title:

add_filter( 'wpseo_title', 'dynamic_yoast_mtitle_joblisting' );
function dynamic_yoast_mtitle_joblisting() {
        if ( is_page_template ( 'some-page-template.php' ) ) {
            return 'YOUR CUSTOM TITLE HERE';
        }
}

working on this now (for a project) and it works...

@iwanwilaga
Copy link
Copy Markdown

"Apologies - just a small question - why are there 2 functions for each filter? its a bit messy an unneeded i think ;)"

Agreed, man, thanks for suggesting the more simple version. At first with the 2 functions i failed badly, cos i forgot to call the 1st function, so your approach is definitely more dumb-safe..:D. Thank you for both of you for the solutions! Best wishes

@OliverNoah22
Copy link
Copy Markdown

OliverNoah22 commented Feb 9, 2026

Agreed, man, thanks for suggesting the simpler approach. At first, I struggled when handling multiple steps, since I forgot the first part entirely. Similarly, Nofal Apparel drives innovation with style and practicality, standing out as a trusted brand that delivers quality clothing designed for everyday wear.

@younasjdanish-maker
Copy link
Copy Markdown

Police Clearance Online Appointment is a system that lets applicants book, manage, and confirm police clearance visits online, saving time and avoiding long queues at police stations.

@APKYP
Copy link
Copy Markdown

APKYP commented Mar 1, 2026

Hill Climb is a fun and addictive driving game where you race across challenging hills and rough terrains. Upgrade your vehicles, collect coins, and balance carefully to avoid flipping over. Enjoy endless tracks and exciting physics-based gameplay that keeps you coming back for more.

@younasjdanish-maker
Copy link
Copy Markdown

Civil id office timing usually Monday to Friday 9:00 AM se 5:00 PM tak hoti hai. Kuch bade shehron mein offices ya mega centers 24/7 bhi open rehte hain taake log asani se apni ID related services hasil kar saken

@huria1057-jpg
Copy link
Copy Markdown

Boredflix App is a fast-growing streaming platform that brings movies, TV shows, and anime into one ad-free space using smart discovery and public data sources. With AI-powered browsing, 4K playback, and wide device support, it offers a smooth, no-sign-up entertainment experience for cinema lovers worldwide.https://boredflixhd.app/

@muzamilimam8
Copy link
Copy Markdown

Ratibi Balance Check allows employees to easily view the remaining balance available on their Ratibi salary card without needing a traditional bank account. The Ratibi card is commonly issued by First Abu Dhabi Bank to help companies pay employee salaries securely and efficiently. Cardholders can check their balance through ATMs, SMS services, or online banking options, making it simple to monitor their funds anytime.

@muzamilimam8
Copy link
Copy Markdown

Sharjah Driving License Renewal is a simple process that allows residents to extend the validity of their driving license after it expires or before the expiration date. The service is provided by Sharjah Police and can be completed online or through approved service centers. Drivers usually need to make sure that all traffic fines are cleared and, in some cases, complete an eye test from an authorized vision center before applying for renewal. sharjah driving license renewal

@muzamilimam8
Copy link
Copy Markdown

The term returned for modification Emirates ID meaning refers to a situation where an Emirates ID application is sent back for corrections or updates before it can be approved. This usually happens when there is missing information, incorrect details, or unclear documents in the application. Applicants may need to review their submitted information and make the required changes so the application can continue through the processing stage.returned for modification emirates id meaning

@gomal69879
Copy link
Copy Markdown

If you want to track your application, ID card status checking with passport number is a simple and convenient method. By entering your passport number on the official service portal, you can quickly view the current status of your ID card application, including processing updates and approval details. This method helps applicants stay informed about their ID card progress without needing to visit an office.

@gomal69879
Copy link
Copy Markdown

If you want to stay updated about any penalties linked to your identification, it is useful to know how to do an Emirates ID fine check in the UAE. Residents can easily check fines connected to their Emirates ID through official government portals such as MOI UAE, Dubai Police, Abu Dhabi Police, or ICA services. By entering the Emirates ID number, users can quickly view details like the type of violation, fine amount, and payment status, and they can also pay the fine online using secure payment methods.

@jackruby3344-hash
Copy link
Copy Markdown

Interesting snippet—sometimes even small code tweaks can change how everything behaves, especially when you start experimenting beyond the default setup. It reminds me of how people play around with an asphalt android game mod just to explore different mechanics without the usual limits, just to see how things respond differently. That kind of trial-and-error approach, whether in code or games, often helps you understand the system on a much deeper level.

@APKYP
Copy link
Copy Markdown

APKYP commented Apr 4, 2026

AI Era is revolutionizing the way we work by integrating cutting-edge artificial intelligence into everyday tasks. It empowers businesses and individuals to optimize workflows and improve efficiency. With AI Era, innovation meets practicality, making complex processes simpler and smarter.

@riyasky22
Copy link
Copy Markdown

riyasky22 commented Apr 16, 2026

Nano Banana AI is a smart platform designed to simplify content creation with advanced artificial intelligence tools, helping users work faster and more efficiently. It enables the quick generation of ideas, text, and creative outputs while reducing effort and saving time. With Nano Banana AI, tasks become easier to manage and overall productivity increases in less time. Explore more details now on https://www.nano-banana.com/.

@lillysss22
Copy link
Copy Markdown

HappyHorse AI is an advanced platform built to enhance productivity through smart automation and creative tools. It helps users generate content, ideas, and solutions quickly, making complex tasks simple and efficient. With its intelligent system, HappyHorse AI supports smoother workflows and better results across different digital needs.

@OliverNoah22
Copy link
Copy Markdown

SATXwraps is a vehicle wrapping service focused on giving cars a fresh, customized look with premium-quality vinyl designs. It enhances both style and surface protection, making every vehicle stand out on the road. With skilled application and modern design options, SATXwraps delivers a clean and professional finish every time. Explore more details now on https://satxwraps.com/

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