Support » Plugin: AMP » Is it possible to incorporate breadcrumbs into reader mode?

  • Resolved learn2love

    (@learn2love)


    To whom it may concern,

    I was wondering if it may be possible to incorporate breadcrumbs onto the reader version of blog posts? Something that could show above the content such as on the regular version of the page: https://learnlove.ca/2020/07/limits-make-me-who-i-am/

    We use Yoast SEO for breadcrumbs. I was wondering if I could just copy the Yoast breadcrumbs code into an AMP file to get it to work. The code we use is here:

    <?php
    if ( function_exists('yoast_breadcrumb') ) {
      yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
    }
    ?>

    Thank you very much for your time and help, I greatly appreciate it and wish you the best,

    Dory

    • This topic was modified 1 year, 2 months ago by learn2love.

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    While you can modify the AMP Reader mode templates to add the same code, probably a better approach is to inject the breadcrumbs with a the_content filter. Without the is_amp_endpoint() check even, this will also add the breadcrumbs to any theme as well so you don’t have to modify the theme files:

    add_filter( 'the_content', static function ( $content ) {
    	if ( 
    		function_exists( 'yoast_breadcrumb' ) 
    		&&
    		function_exists( 'is_amp_endpoint' )
    		&& 
    		is_amp_endpoint() 
    	) {
    		$content = yoast_breadcrumb( '<p id="breadcrumbs">','</p>', false ) . "\n\n$content";
    	}
    	return $content;
    } );
    Thread Starter learn2love

    (@learn2love)

    Thank you for your time and help, I greatly appreciate it!

    We tried to include this in the single.php file so that it would show up on all posts, but this unfortunately did not work for us. I wonder if maybe it is an issue with the cache or our theme. Thank you very much anyway for your time and help! We’ll keep trying. In the meanwhile, this is good enough without the breadcrumbs. We are so happy with how it helped to speed up the page!

    Very best wishes,

    Dory

    Plugin Author Weston Ruter

    (@westonruter)

    Putting this plugin code in the single.php file would probably not be correct. It would be better to put it in a separate plugin that you activate separately.

    For example, create a file like wp-content/plugins/learn2love-amp-breadcrumbs.php and put in the file:

    <?php
    /**
     * Plugin Name: learn2love AMP Breadcrumbs
     */
    
    add_filter( 'the_content', static function ( $content ) {
    	if ( 
    		function_exists( 'yoast_breadcrumb' ) 
    		&&
    		function_exists( 'is_amp_endpoint' )
    		&& 
    		is_amp_endpoint() 
    	) {
    		$content = yoast_breadcrumb( '<p id="breadcrumbs">','</p>', false ) . "\n\n$content";
    	}
    	return $content;
    } );

    Then activate the plugin.

    Thread Starter learn2love

    (@learn2love)

    Thank you for sharing this with me, I greatly appreciate your time and help

    Thread Starter learn2love

    (@learn2love)

    We had some trouble creating a new plugin, but just placed the add_filter command instead the functions.php file of the theme and it seems to work just fine.

    I greatly appreciate your time and help!

    Dory

    Plugin Author Weston Ruter

    (@westonruter)

    Yes, putting it in the theme’s functions.php will work for the current Reader mode. However, when/if you switch to use a new Reader theme in v2.0 then you’ll need to move it to a plugin.

    Thread Starter learn2love

    (@learn2love)

    Okay, I understand. Thank you very much for this! I appreciate your time and help.

    We tried uploading the plugin as a .PHP file and it resulted in an error saying that only .zip files can be installed. We will try to compress it then and reupload to be compatible with the next release. I greatly appreciate all of your time in helping me with this tool,

    Dory

    Plugin Support James Osborne

    (@jamesosborne)

    Did you try and compress the php file into a .zip file and upload? Let us know how you get on after doing so.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Is it possible to incorporate breadcrumbs into reader mode?’ is closed to new replies.