Yoast - Custom Taxonomy - primary category

I have a Custom Taxonomy with the name country. I would like to display the primary category only. I have the yoast plugin installed and that is how I'm setting the primary category. I'm using this code I found to do the same thing but with post categories and it works well. <?php $primaryCat = new WPSEO_Primary_Term('category', get_the_ID()); $primaryCat = $primaryCat->get_primary_term(); $primaryCat = get_cat_name($primaryCat); $categories = get_the_category(); foreach( $categories as $category ) { $defaultCat = $category->name; $defaultCatLink = get_category_link( $category->term_id …
Category: Web

Workaround for og:image unsupported webp image type, Yoast SEO?

My site Beta Fox uses Yoast SEO plugin to help deal with SEO common practices, however an issue has arisen. In beginning of last year WordPress didn't fully support webp image types, neither Yoast SEO. Things changed near the end of year, but Yoast SEO unbelievably refuses to support webp (the types Google is forcing upon on us to use). The problem is the fact there's no open graph for image attachments in any page of the site, so that …
Category: Web

Replace default og:image tag YOAST

I'm trying to replace the default image picked by yoast (featured image) with a custom with the relative og:image:width and og:image:height, but seems a mission impossible! I tryed with this: function my_own_og_function() { $my_image_url = 'http://www.mywebsite.net/wp-content/uploads/TEST-A.jpg'; $GLOBALS['wpseo_og']->image( $my_image_url ); // This will echo out the og tag in line with other WPSEO og tags } add_action( 'wpseo_opengraph', 'my_own_og_function', 29 ); But yes, the image is replaced, only is without og:image:width and og:image:height So i'm wondering, is there away to make …
Category: Web

WordPress: Export/Import Yoast meta title & description to custom taxonomy

I want to export the Yoast meta title & description from a custom taxonomy with the WP All Export. Unfortunately there is no direct way with the plugin to do that. There is an extra WP All Export addon for Yoast but it doesn't work for custom taxonomies. I tried to use a custom function in the export to get the title and description. But my function doesn't work either. Im not sure why. Here's my current function: function yoast_wpseo_title($value) …
Category: Web

SEO meta description and title tag Yoast SEO

I am using Yoast SEO and a custom header. this obv means that any code that yoast uses to input all the seo stuff such as title tag and meta description wont be there. I solved the title tag by using this code: <title><?php /* * Print the <title> tag based on what is being viewed. */ global $page, $paged; wp_title( '|', true, 'right' ); // Add the blog name. bloginfo( 'name' ); // Add the blog description for the …
Category: Web

Rewriting URL with child pages

I have a parent page with the URL example.com/the-boats And then child pages like so: the-boats/story the-boats/cast the-boats/articles etc... Many visitors type example.com/boats example.com/cast So when they do this I want to redirect them to /the-boats /the-boats/story etc... I cannot figure out how to do this. I've tried 3 strategies thus far function custom_rewrite_basic() { add_rewrite_rule('^boats/?$', 'index.php?pagename=the-boats/$matches[2]', 'top'); flush_rewrite_rules(); } add_action('init', 'custom_rewrite_basic'); and... add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2); function my_redirect_canonical($redirect_url, $requested_url) { if ( $requested_url == 'https://example.com/boats') { $redirect_url = 'https://example.com/the-boats'; …
Category: Web

How to use the Yoast SEO wpseo_canonical filter to set a canonical URL for /, /au/ & /uk/ sites in a MU environment

Our company has markets in USA, UK & Australia. We've just started using WP MU on our development server where the USA/global version is @ www.example.com, and then there are www.example.com/uk/ & www.example.com/au/. We're probably going to create an AJAX function to redirect the visitor based on their geographical location to the appropriate website, with www.example.com being the catch-all. I've come across the Yoast SEO wpseo_canonical filter which might help us set a canonical URL for all of our posts …
Category: Web

Replace Yoast og:image in single custom post type

I'm trying to replace the custom yoast og:image in a specific post type to use a custom meta field instead of the featured image. What I got so far is: function my_wpseo_opengraph() { global $post; if (is_singular('job_listing')) { $og_image = get_post_meta($post->ID, 'pp_job_header_bg', TRUE); if (!empty ($og_image)) { $GLOBALS['wpseo_og']->image($og_image); } } } add_action('wpseo_opengraph', 'my_wpseo_opengraph', 29); However, while viewing the source code, it seems that the code won't replace the default og:image, it adds a second og:image. How do I replace it?
Category: Web

Hard-code SEO Title defaults across all sites on a multisite

I am using Yoast on a multisite with hundreds of sites and thousands of posts and I would like to make sure that the SEO title always ends with | Sitename and not have to rely on authors not changing the variables while editing the SEO title. I could update the default on the "Yoast SEO Search Appearance" settings page to not have the sitename and add a filter to add the sitename on output. I know how to do …
Category: Web

Display Yoast meta-description `wpseo_desc` within loop of categories and fail silently if no data is set

I want to output the Yoast SEO category meta-description within a custom loop. Current code (below) works if there is a meta-description present. However, if no category meta-description is set it breaks. Is there a better way to write this so that it fails silently if no meta-description is set <?php $popular_topics = get_field('popular_topics'); if( $popular_topics ): foreach( $popular_topics as $topic ): $id = $topic->term_id; $meta = get_option( 'wpseo_taxonomy_meta' ); $meta_desc = $meta['category'][$id]['wpseo_desc']; ?> <p class="my-paragraph"> <?php echo esc_html( $meta_desc …
Category: Web

Set default image for twitter cards with Yoast?

I've figured out how to use Yoast to set a Twitter card image for each page (enable Yoast, then go to the page and set the image and description manually in the "Yoast SEO" settings). But how do I set a default Twitter card image and description for all the pages on my site? I have many pages, and really don't want to have to manually set a card and image for all of them.
Category: Web

Yoast Metadata API to adjust/override the meta description

I wanted to use the following function to override the Yoast meta description: add_filter('wpseo_metadesc','custom_meta'); function custom_meta( $desc ){ if (/* do your test here to check template or any other values*/) { $desc = "Change the description"; } return $desc; } However, Yoast SEO support recommends the Metadata API. From this page, I understand I can use the wpseo_metadesc filter to adjust the Meta_Description_Presenter, but I am unsure how it is done; I am not a programmer. I'd love some …
Category: Web

Overwrite YoastSEO meta-tags with another page's

I'm writing a custom Wordpress theme and for a specific page I need to overwrite its meta-tags (printed by YoastSEO) with the meta-tags of another page I already know the ID of. I cannot just change the original page meta-tags because the replacement changes based off a custom field in the page. I've tried this, but apparently wp_head() is unaffected by the_post()... <head> ... <?php if (...) { $meta_page = new WP_Query([ 'page_id' => $meta_page_id ]); while ( $meta_page->have_posts() ) …
Category: Web

Yoast Breadcrumbs add another level for the tag page

I have a page structure like this: "Home > Category > Sub Category > Tag", but when I visit the tag page, the breadcrumbs only shows: "Home > Category > Sub Category" where the tag is gone and the Sub Category isn't even linked. How can I make sure that the Sub Category has a hyperlink and to add another level to the breadcrumbs, namely the current tag page? I understand that I can override the yoast_breadcrumb() function in functions.php, …
Category: Web

custom wordpress theme and yoast seo injecting text in body

I have created a custom PHP Wordpress theme using HTML5Blank Template and Advanced Custom Fields, however, whenever the Yoast SEO plugin is activated it injects "view article" twice as text in the top of the page. The behaviour seems odd but it doesn't inject it into the HTML head but the body. Has anyone experienced this issue and have any fixes for it? I am forced to disable the plugin until I can patch this issue as it effects all …
Category: Web

Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)

So to increase my SEO score I require all tag pages to have a H1 title, for example website.com/tags/taghere would need the title: <h1>TagHere</h1> or simply <h1>taghere</h1> I can go through each tag manually and add them but this would beyond tiresome to do for 1000+ tags, we're running the Avada theme and I can't see any option anywhere to do this automatically. Is there a way I can create a function for the functions.php to do it automatically? Essentially …
Category: Web

Post Thumbnail missing when using webp format while sharing

I have a problem when I upload a featured image for my post in jpg format, I get the featured image's thumbnail while sharing my post through any kind of messenger e.g whatsapp etc. But when I try to upload the featured image in webp format. My post thumbnail gets missing while sharing it. As far as I have studied about it till last year og:image for webp wasn't supported in wordpress. Is it still the same. Is there any …
Category: Web

Link custom post type to parent page and show in slug / breadcrumb

I am using the Custom Post Type UI plugin to add custom post types to our website. We now created a CPT called IPDC. For this custom post type, we would like to have the option to link every IPDC page to a parent page, the parent page being a default Wordpress page. I guess I could do this by adding a custom field, but how do I manage the slug and breadcrumb in that case? For example. The IPDC …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.