- This topic has 3 replies, 3 voices, and was last updated 4 years, 11 months ago by
David.
-
AuthorPosts
-
April 29, 2021 at 3:22 pm #1756472
Bozlur
Hi,
I don’t use any SEO Plugins like Yoast or Rankmath. So, without using seo plugins, how can I add Add custom Post Meta Title, Meta Description and Keywords for each post in GP Premium.April 29, 2021 at 7:52 pm #1756624Elvin
StaffCustomer SupportHi there,
You can try these.
https://wpdatatables.com/how-to-add-meta-tags-in-wordpress-without-a-plugin/
https://gretathemes.com/seo-add-meta-tags-without-plugins/While they’re not GeneratePress specific, it shouldn’t matter anyway as the functions are WordPress core.
It’s a bit tedious. That’s why most users use plugins for this. 🙂
April 30, 2021 at 12:23 am #1756975Bozlur
Hi Elvin,
Thank you for your reply. Let me clear my question so that you can understand that its GeneratePress specific. There was hook/section elements in GP. So Is it possible to add Add Post Meta Title, Meta Description and Keywords in every post with hooks? If yes then how?April 30, 2021 at 5:13 am #1757362David
StaffCustomer SupportHi there,
you can convert either of the codes provided in the posts that Elvin provided.
Heres one of those codes.function gretathemes_meta_description() { global $post; if ( is_singular() ) { $des_post = strip_tags( $post->post_content ); $des_post = strip_shortcodes( $post->post_content ); $des_post = str_replace( array("\n", "\r", "\t"), ' ', $des_post ); $des_post = mb_substr( $des_post, 0, 300, 'utf8' ); echo '<meta name="description" content="' . $des_post . '" />' . "\n"; } if ( is_home() ) { echo '<meta name="description" content="' . get_bloginfo( "description" ) . '" />' . "\n"; } if ( is_category() ) { $des_cat = strip_tags(category_description()); echo '<meta name="description" content="' . $des_cat . '" />' . "\n"; } } add_action( 'wp_head', 'gretathemes_meta_description');The code is using the
add_actionfunction to hook in the custom function into thewp_head. thats not required as the Hook Element does that.You would use a Hook Element >
wp_headinstead.Then stripping out the code from the function.
The code uses conditonal tags such asif ( is_singular() ) {for displaying the Meta Description, this is not required as this would be the Display Rule Locations.You would use Display Rules Location:
All Singularfor that condition.This leaves you with this code to add to your Hook which will add the Meta Description:
<?php global $post; $des_post = strip_tags( $post->post_content ); $des_post = strip_shortcodes( $post->post_content ); $des_post = str_replace( array("\n", "\r", "\t"), ' ', $des_post ); $des_post = mb_substr( $des_post, 0, 300, 'utf8' ); echo '<meta name="description" content="' . $des_post . '" />' . "\n"; ?>Note the global $post; will be required in the subsequent meta functions. And all must be wrapped in
<?php ?>tags.
And in the Hook settings you must check Execute PHP.You would need to create a separate hook for each of the different
ifconditions in that code.For Keywords – well there isn’t a meta field for those in WP – so you would need to create Custom Fields for those and use the
get_post_meta()to grab that data.https://developer.wordpress.org/reference/functions/get_post_meta/
Hope that helps.
-
AuthorPosts
- You must be logged in to reply to this topic.