Possible Approach
Hi @dsstoikov,
That’s a good question. I can see how that tab on the non-AMP page would be important to display on the AMP page:
Is this some of the markup you were referring to?
http://www.mapea.eu/pfitemfinder/апартамент-под-наем-пловдив-кършияка/
If so, it’s possible to add content like that to the bottom of the post content. You might copy the PHP that outputs that into a callback like this, or copy it into a template. Of course, this won’t be a good solution if it uses too many lines of PHP.
add_filter( 'the_content', function( $content ) {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
$content .= 'Paste PHP here';
}
return $content;
} );
The result could be something like:
You could also style it, using add_action( 'amp_post_template_css', ...
https://github.com/Automattic/amp-wp/wiki/Legacy-Templating-And-Customization#logo-only
It looks like that site is using the Point Finder theme:
https://themeforest.net/item/point-finder-directory-wordpress-theme/10298703
Ok, great, thanks. Any more details how to create the template and where exactly to save it? Much appreciate it.
Example Template Approach
Hi @dsstoikov,
You could create a template like my-tab.php
with the PHP that outputs the tab.
In the example below, that my-tab.php
file would be in the directory templates/
, but adjust it as you’d like.
In you theme’s functions.php
, place:
/**
* On AMP pages, append the contents of a template at the bottom of the post content.
*
* @param string $content The post content.
* @return string $content Filtered content.
*/
add_filter( 'the_content', function( $content ) {
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
ob_start();
get_template_part( 'templates/my-tab' );
$content .= ob_get_clean();
}
return $content;
} );
Hi Ryan, I did what you asked me to but the amp version is still incomplete I mean it does not show the tabs.
What I did so far is I created a file named “my-tab.php” and uploaded it to vc_templates/ folder and pasted the following content into the file
“add_filter( ‘the_content’, function( $content ) {
if ( function_exists( ‘is_amp_endpoint’ ) && is_amp_endpoint() ) {
$content .= ‘Paste PHP here’;
}
return $content;
} );”
Then opened functions.php file and pasted the following at the bottom of the file
“/**
* On AMP pages, append the contents of a template at the bottom of the post content.
*
* @param string $content The post content.
* @return string $content Filtered content.
*/
add_filter( ‘the_content’, function( $content ) {
if ( function_exists( ‘is_amp_endpoint’ ) && is_amp_endpoint() ) {
ob_start();
get_template_part( ‘templates/my-tab’ );
$content .= ob_get_clean();
}
return $content;
} );”
Is pasting the above at the bottom of the file ok or I need to paste somewhere else?
Is all I have done correct as I still cannot get the tabs showing in the amp version of the site?
Regards