- This topic has 5 replies, 2 voices, and was last updated 6 years, 11 months ago by Tom.
-
AuthorPosts
-
May 10, 2017 at 7:35 am #316322Vinai
I want to use my own custom fields (created using Advanced Custom Fields) to appear in the Page Meta Title and Description, for all pages.
Is there a simple way to get this done? I am using the Premium edition of GeneratePress.
Thanks,
VinMay 10, 2017 at 7:37 am #316323VinaiI have tried the code below in the functions.php of the blank generatepress child theme. But the custom meta description field value did not appear in the source code.
/*Display custom meta description or the post excerpt */ function add_custom_meta_des(){ #Homepage Meta Description if( is_home() || is_front_page() ){ $meta_des = "Enter your homepage meta description here"; #Edit here echo '<meta name="description" content="' . $meta_des . '" />'; } #Single Page Meta Description if( is_single() ){ $des = get_post_meta( get_the_id(), 'description', true); if( ! empty( $des ) ){ $meta_des = esc_html($des); echo '<meta name="description" content="' . $meta_des . '" />'; } }} add_action( 'wp_head', 'add_custom_meta_des', 4 );
May 10, 2017 at 8:03 am #316362TomLead DeveloperLead DeveloperSomething like that should work. Can you link me to your site?
May 10, 2017 at 8:51 am #316390VinaiThanks Tom. I have emailed you the login details of the site, and the page in question. Kindly look into it. If I should post the login details here, let me know, and I’ll do so.
Thanks,
VinMay 11, 2017 at 2:32 am #316660VinaiHi,
I have now managed to get the post title and meta generated using the code below, in the child theme’s functions.php file.
$des = get_post_meta(get_the_ID(), ‘meta_title’, true);
if( ! empty( $des ) ){
$meta_des = esc_html($des);
echo ‘<title>’ . $meta_des . ‘</title>’ .”\r\n”;
}However, on viewing the source code, the wp_head() function generates the page title using the Site Title and Site Tagline automatically, and so now I am seeing 2 titles in the source code head of the page.
How do I suppress the standard default site title and tagline from displaying on the site. I have already checked the “Hide Site Title” & Tagline in the “Site Identity” of the theme.
Thanks,
May 11, 2017 at 9:18 am #316777TomLead DeveloperLead DeveloperIs there any reason you’re wanting to go this route instead of using a plugin like Yoast SEO?
WordPress itself adds the title tag (https://codex.wordpress.org/Title_Tag), so you would need to filter it with PHP if you don’t want to use a plugin.
-
AuthorPosts
- You must be logged in to reply to this topic.