Support » Plugin: AMP for WordPress » Minimum information

  • Resolved dsstoikov

    (@dsstoikov)



    Hi, just wanted to ask if there is a minimum information that one can keep into the amp page? This what I mean is on the responsive page( above is amp version ) I have a tab with information about a property like price, square meters etc but on the amp version I am missing this information which is critically important. Question is if I can set up the amp plugin what part of the responsive page to include into the amp version.
    I am sure this it’s valid for many other site owners.

    Regards

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Ryan Kienstra

    (@ryankienstra)

    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/апартамент-под-наем-пловдив-кършияка/
    Tab price square meters

    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:
    Content added the content

    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.

    Plugin Support Ryan Kienstra

    (@ryankienstra)

    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;
    } );
    
    • This reply was modified 5 months, 3 weeks ago by  Ryan Kienstra.

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.