In Meta Title or description?
-
Hello
If you add [y] in the Title of a Page, what will happen in the Meta SEO Title?
In other words, can you add the shortcode in the SEO Title in Yoast and in the Meta Description? What will Google display then on their search result pages?
Thank you
I mean will Google
-
Hello @masterhealerwp
Out of the box Yoast doesn’t support shortcode on meta tags.
You can found solution on web for enable shortcode on meta: https://letmegooglethat.com/?q=Custom+Shortcodes+in+Yoast+SEOBest regards
- This reply was modified 2 years, 2 months ago by kgmservizi.
@kgmservizi thank you so much.
Since I’m not a coder, can you please confirm I did things correctly:
1. I put this code snippet in functions.php:
add_filter( 'wpseo_title', 'do_shortcode' ); add_filter( 'wpseo_metadesc', 'do_shortcode' ); add_filter( 'the_title', 'do_shortcode' ); add_shortcode( 'year' , 'current_year' ); function current_year() { $year = date("Y"); return "$year"; }
2. Then I put [year] in my SEO Title, please check this here.
As you can see [year] remains Yer even in the Google Preview on the screenshot.Is this ok or did I miss something?
This is out of my support but I can try to help.
If you need shortcode only in meta title you can use only this code inside functions.php (or custom plugin)
add_filter( 'wpseo_title', 'do_shortcode' ); add_shortcode( 'year' , 'current_year' ); function current_year() { $year = date("Y"); return "$year"; }
If you want use my plugin you can only add the filter line
add_filter( 'wpseo_title', 'do_shortcode' );
And [y] in SEO Title.
If you need shortcode also in meta desc add also
add_filter( 'wpseo_metadesc', 'do_shortcode' );
in WordPress post title
add_filter( 'the_title', 'do_shortcode' );
Best regards
Thanks you so much for your help.
I’m a bit confused.1 – Do I need to add anything in functions.php if I already have installed your plugin?
2 – To get the year in the WordPress Post title, why would I need to add this:
add_filter( 'the_title', 'do_shortcode' );
I already have your plugin installed. Is it not enough?
Thank you again
@masterhealerwp it is not enough because my plugin only add shortcode in default place, we don’t add filter in “the_title” or Yoast meta because it is a choiche of developer (security, code, etc… choice).
You need to add filter for what you want. You can choice one or more of this.
Meta Title Yoast (this is for meta title in Yoast as you want)
add_filter( 'wpseo_title', 'do_shortcode' );
Meta Desc Yoast
add_filter( 'wpseo_metadesc', 'do_shortcode' );
Title Post
add_filter( 'the_title', 'do_shortcode' );
—
If you want make what I see in your screenshot add to your functions.php this filter.
add_filter( 'wpseo_title', 'do_shortcode' );
and in your Yoast SEO Meta Title use [y]
If you want current year also in Post Title, add also this filter in your functions.php.
add_filter( 'the_title', 'do_shortcode' );
and [y] in your post title.
Regards
- This reply was modified 2 years, 2 months ago by kgmservizi.
Thanks a lot for your reply.
1 – To summarize, I cannot add shortcode anywhere if I ONLY installed your plugin without adding anything in functions.php?
2 – Please have a look at this page:
a. I installed your plugin.
b. I added [y] in the Page title.
Result: The [y] is kept as is in the published page (= not interpretated and replaced by “2022”).
=> is this a normal behavior?3 – If want already have a shortcode in my Page Title, do I need to replace it in the Yoast SEO Title by another shortcode since Yoast copy the exact Page Title in their Yoast SEO Title?
4 – How long will your plugin be maintained? In other words, can it break after WordPress updates? What will then happen to all the pages where I have used shortcode with your plugin?
Thanks so much for your support. Regards,
Hi @masterhealerwp you need a developer that understand your requests.
1. My plugin work in all place where WordPress allow shortcode. Not in post Title and Yoast Meta, because it isn’t place where shortcode work as default.
2. Yes it is a normal behavior, you need this filter in your functions.php
add_filter( 'wpseo_title', 'do_shortcode' );
3. I don’t know, I’ve never used before.
4. My plugin is always maintained, shortcode so easy usually don’t break in a new major realease of WordPress.
Regards
Thank you again for your support. Still not there yet…
1. I added this to Functions.php:
/*Enable shortcode for Post Title, SEO Title & Desc for plugin Current Year and Symbols Shortcode*/
add_filter( ‘wpseo_title’, ‘do_shortcode’ );
add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );
add_filter( ‘the_title’, ‘do_shortcode’ );2. The [y] is now interpretated well in the Page Title.
But not for the SEO Title (please note that I’m using the SEOPress plugin). Can you see the Google Preview they show on the right hand-side of the screenshot. The [y] is still there when it should have been replaced by 2022.@masterhealerwp you can use
%%currentyear%%
to display the current year in your title and metas:https://www.seopress.org/support/guides/manage-titles-meta-descriptions/
You can also use this filter to add your own dynamic variable:
- This reply was modified 2 years, 2 months ago by Benjamin Denis.
@kgmservizi My questions remains valid about your plugin, but note I moved away from SEOPRess to use YOAST instead. Thank you
If you added the correct filters shortcode work in Yoast SEO, maybe you need some day that Google correct index the page.
For any other question of Yoast I suggest to ask in Yoast SEO support forum.
Best regards
- The topic ‘In Meta Title or description?’ is closed to new replies.