Last active
March 16, 2026 11:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.