Hi I´m having a hard time getting my og metatags to change dynamically( banging my head against the wall). I want to change the og:description dynamically based on an input field.
Here is what I have been able do figure out so far:
$og_description = $_POST['question'];
$custom_input = array("value" => $og_description);
<meta property="fb:app_id" content="xxxxxxxxxxxxxx" />
<meta property="og:site_name" content="Site name etc.. " />
<meta property="og:description" content=" <?php echo "this is {$custom_input['value']} !"; ?>" />
It works just fine outside the meta tags, but for some reason I just end up with it echoing the text "this is".
Any help would be greatly appreciated:)
Related
In my Next.js app I'm trying to insert og meta tags with dynamic content on a product page. So the content of the meta tags will change based on the product data fetched from server.
I am fetching product data using getServerSideProps and passing product data to page component as props.
export const getServerSideProps = wrapper.getServerSideProps(
store => async (context) => {
const response = await fetch(url, {
method: 'GET',
});
const data = await response.json();
return {
props: {
host: context.req.headers.host,
product: data.product
}
}
}
)
First Approach
I tried to insert meta tags directly on my product page component within <Head> component. Here meta tags even with static conetnt are not showing in page source.
const Product = ({product}) => {
return (
product ?
<>
<Head>
<title>{product.title}</title>
<meta name="description"
content={product.description}/>
<meta property="og:title" content={product.title}/>
<meta property="og:type" content="video.movie"/>
<meta property="og:url" content={`${props.host}/products/${product.slug}`}/>
<meta property="og:description" content={product.description}/>
<meta property="og:image" content={product.thumbnail}/>
</Head>
<Course/>
</> : null
);
};
Second Approach
return (
<Html lang="en">
<Head>
{/*<meta property="og:image" content="https://static.onlinevideobooks.com/abed1e5658b3ad23c38c22646968e4f2/files/media/images/2022/04/5b0645b9-ab03-4233-b5f3-86b092d4062b/conversions/cad47d2beb9143eab3d65ea4a75b0b0e-1280x720.webp" />*/}
{/*<title>your keyword rich title of the website and/or webpage</title>*/}
<meta name="description"
content="description of your website/webpage, make sure you use keywords!"/>
<meta property="og:title" content="short title of your website/webpage"/>
<meta property="og:type" content="video.movie"/>
<meta property="og:url" content="https://example.com/"/>
<meta property="og:description" content="description of your website/webpage"/>
<meta property="og:image"
content="https://example.com/image"/>
</Head>
</Html>
);
I tried inserting meta tags within <Head> in _document.js file. Here I am passing only static conetnt as I don't have dynamic data in _document.js. This time meta tags are showing up in page source and I can also preview them on facebook.
Third Approach
Then I try to insert those tag in _app.js file as I receive pageProps in this component.
Unfortunately when I pass dynamic content in meta tags like first approach, they do not show up in page source but they do when I pass static conetnt similar to second approach.
full _app.js code gist
UPDATE
As regard to my third approach, I checked once again and surprisingly I can see all meta tags in page source when inserted either with static or dynamic content in _app.js. I can preview the url when content is static but when content is dynamic I can not preview the url using either Facebook debug or Open graph
My Next.js version is 12.2.0
It's possible that the code you have in your _app.js is blocking the meta tags from being rendered. The "View page source" in browsers will not wait for client code to finish rendering. You can verify this and click "View page source" from your browser. Do you see any of the HTML you are expecting, for example do you see your meta tags and product html?
I expect that you probably don't see anything except some static HTML tags. One thing you could try is moving your use of hooks and rendering logic down into its own MainLayout component.
You can then try your first approach where you do something like this:
const Product = ({product}) => {
return (
product ?
<>
<Head>
<title>{product.title}</title>
<meta name="description"
content={product.description}/>
<meta property="og:title" content={product.title}/>
<meta property="og:type" content="video.movie"/>
<meta property="og:url" content={`${props.host}/products/${product.slug}`}/>
<meta property="og:description" content={product.description}/>
<meta property="og:image" content={product.thumbnail}/>
</Head>
<MainLayout>
<Course/>
<MainLayout>
</> : null
);
};
Where MainLayout contains all the logic you have in your _app.js. This should keep your actual _app.js free of any client side code that is blocking the meta tags from rendering.
Basically we want to utitlize Next.js static optimization and have it pre-render the meta tags for your page so that the browser and web crawlers get the data without having to wait for any client side rendering.
Hopefully this helps someone, but my issue was the placement of the <Head> tags within _app.js. For some reason, when it was nested under <Auth0ProviderWithHistory> the meta tags would not render, moving it outside of this gave me victory.
Broken
<Auth0ProviderWithHistory>
<Head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{openGraphData.map((og) => (
<meta {...og} />
))}
<title>{pageProps.title}</title>
</Head>
<CssBaseline>
<div className="page-layout">
<NavBar />
<Component {...pageProps} />
<Footer />
</div>
</CssBaseline>
</Auth0ProviderWithHistory>
Fixed
<span>
<Head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{openGraphData.map((og) => (
<meta {...og} />
))}
<title>{pageProps.title}</title>
</Head>
<Auth0ProviderWithHistory>
<CssBaseline>
<div className="page-layout">
<NavBar />
<Component {...pageProps} />
<Footer />
</div>
</CssBaseline>
</Auth0ProviderWithHistory>
</span>
Not sure what's going under the hood, but removing the Head tag resolves this for me.
I just put my meta tags without nesting them inside Head, and it worked.
I have multiple image's meta tag generated by Yoast plugin, The other I have no idea, I'm trying to remove the first meta so that I can be able to get preview images when sharing the post via WhatsApp.
I have looked into the header in WordPress there is no meta tag shown when viewing the source code on browser saw multiple image meta appeared on a single post. website is benjavibe.com
Below is my header tags
<meta property="og:image" content="https://benjavibe.com/wp-content/uploads/2019/05/Usilie.jpg" />
<link rel="icon" type="image/png" href="https://benjavibe.com/wp-content/uploads/2018/08/Music-icon-300x300.png">
<meta name="description" content="Tanzania Number One Website that give you all trending Entertainment News. New Music and New Videos and Many more." />
<link rel="canonical" href="https://benjavibe.com/mo-music-ft-galatone-usilie-audio-download/" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="article" />
<meta property="og:title" content="Mo music ft Galatone - Usilie | Audio Download - BENJA VIBE MUSIC TANZANIA WEBSITE FOR INTERTAINMENT" />
<meta property="og:description" content="Tanzania Number One Website that give you all trending Entertainment News. New Music and New Videos and Many more." />
<meta property="og:url" content="https://benjavibe.com/mo-music-ft-galatone-usilie-audio-download/" />
<meta property="og:image" content="https://benjavibe.com/wp-content/uploads/2019/05/Usilie.jpg" />
<meta property="og:image:secure_url" content="https://benjavibe.com/wp-content/uploads/2019/05/Usilie.jpg" />
<meta property="og:image:width" content="768" />
<meta property="og:image:height" content="768" />
<meta property="og:image:alt" content="Mo music ft Galatone - Usilie" />
You can use the wpseo_metadesc filter to disable the meta description tag. You’ll need to add the code below to the functions.php file of your theme.
add_filter( ‘wpseo_metadesc’, ‘__return_false’ );
If you need more information about this I would recommend you to follow this blog post
Remove Yoast SEO Meta Tags
I have come with the solution to remove meta which you want to remove from header,
i hope this will helps you.
You can remove some of the header stuff with the following.
// remove unncessary header info
function remove_header_meta() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
}
add_action('init', 'remove_header_meta');
The default installation does not include stuff like meta keywords, so that is either a theme or plugin that you are using.
UPDATED
Please check update in the following answer
add_filter('wpseo_pre_analysis_post_content', 'mysite_opengraph_content');
function mysite_opengraph_content($val) {
return '';
}
Updated
function mysite_opengraph_content($val) {
return preg_replace("/<img[^>]+\>/i", "", $val);
}
add_filter('wpseo_pre_analysis_post_content', 'mysite_opengraph_content');
Hope this helps you.
I am working on a Wordpress plugin to post WordPress post on Fb as an SWF video.
I was able to post to FB and worked perfectly before 14-05-15. But Now when I make a post, it is only posting the link of the page*.
When I debug it with https://developers.facebook.com/tools/debug it is showing a critical error
"Error parsing input url,No data was cached or no data was scrapped".
On clicking "Fetch New Scrape Information" it is showing two critical Errors.
"Error parsing input url, No data was cached or no data was scrapped"*
and
CURL Error:RECV_ERROR receieved HTTP code 502 from proxy after connect*
Again When I click "Fetch New Scrape Information" All the meta tags get fetched and showing my Post.
When I Refresh Share attachment,It will displayed perfectly. But I needed to show this from the first time when I post from WP.
<meta property="og:title" content="<?php echo $data['title']; ?>" />
<meta property="og:type" content="website"/>
<meta property="og:description" content="<?php echo $data['descripton']; ?>" />
<meta property="og:image" content="<?php echo $data["preview_img"]; ?>" />
<meta property="og:image:width" content="300" />
<meta property="og:image:height" content="300" />
<meta property="og:site_name" content="<?php echo $data['title']; ?>"/>
<meta property="og:video" content="<?php echo WPFBAP_SWF.'fbap.swf?wpContent='.urlencode($data["content"]).'&bg_clr='.$data["bg_color"].'&bg_image='.$data["bg_image"].'&font_color='.$data["font_color"].'&repeat='.$data["image_fill"].'&video_url='.$data["video_id"]; ?>" />
<meta property="og:video:type" content="application/x-shockwave-flash">
<meta property="og:video:width" content="400">
<meta property="og:video:height" content="360">
These are the meta tags I am using. What is Wrong ?
So i have my main meta tags e.g keywords, description..
But on specific sites i want to add a class named metatags where i can insert individual meta tags for the site.
Now my problem is that i don't know how to fetch those. I need a fallback so when i don't have my metatags class, the standard metatags will be used. But when i have my metatags class added they should be shown as well.
I tried it like this and wrote into the section on the pagelayout.tpl :
{let node_metas=fetch(content, node, hash(node_id, $module_result.node_id))}
{if eq( $node_metas.object.data_map.meta_description.content,""}
<meta name="description" content="{$site.meta.description|wash}">
{else}
<meta name="description" content="{$node_metas.object.data_map.meta_description.content|wash}">
{/if}
{if eq( $node_metas.object.data_map.meta_keys.content,""}
<meta name="keywords" content="{$site.meta.keywords|wash}">
{else}
<meta name="keywords" content="{$node_metas.object.data_map.meta_keys.content|wash}">
{/if}
{/let}
Does anyone have an idea why it's not working? I'm still new to ezpublish so i'm thankful for any help !
try this in your page_head.tpl
{def $currentNode = fetch( 'content', 'node', hash( 'node_id', ezpagedata().node_id ))}
{if $currentNode.data_map.meta_tag_description.has_content}
<meta name="description" content="{$currentNode.data_map.meta_tag_description.content|wash}">
{else}
<meta name="description" content="{$site.meta.description|wash}">
{/if}
My website has lots of seperate articles and I need a way to automatically create the OG tags for each notice.
I have filled the OG tags, but it seems wrong while testing it on FB debugger.
Code below:
<meta property="og:site_name" content="Site Name (Can be Static)"/>
<meta property="og:type" content="article"/>
<meta property="og:title" content="<?php echo $title;?>"/>
<meta property="og:description" content="<?php echo $content;?>" />
<meta property="og:url" content="http://url.com/index.php?action=show&type=<?php echo $type;?>&id=<?php echo $id;?>"/>
<meta property="og:image" content="something.php" />
<meta property="fb:admins" content="someid"/>
Notice attributes:
Title = $title
Content = $content
Notice type = $type
ID = $ID
It's all dynamic.
How to fix that??
Thanks
Have you add that line too ?
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# http://ogp.me/ns/fb/[your name space]#">
Which kind of error do you get from the Linter ?