• Resolved jodamo5

    (@jodamo5)


    Hi Bill. Can you please provide some guidance on using the be_subpages_page_title filter?

    I have tried to follow this Alternative link title post, but I can’t get it working.

    I have used Advanced Custom Fields to add a meta_key called be_alt_link_title on the postmeta table. I have added an alternative title to a page and can see it in the postmeta table in SQL. I then added the code from your post https://gist.github.com/billerickson/eae1345d8df6c45c47aa to my child theme’s functions.php file:

    /**
     * Alternate Title for Subpages
     *
     * @author Bill Erickson
     * @link https://gist.github.com/billerickson/eae1345d8df6c45c47aa
     *
     * @param string $title
     * @param object $subpage
     * @return string $title
     */
    function be_subpages_alternate_title( $title, $subpage ) {
    	$alt = esc_attr( get_post_meta( $subpage->ID, 'be_alt_link_title', true ) );
    	if( $alt )
    		$title = $alt;
    
    	return $title;
    }
    add_filter( 'be_subpages_page_title', 'be_subpages_alternate_title', 10, 2 );

    My expectation is that the title of that page will change in the sidebar and will show the alternative title. But nothing is changing. It is still just showing the full title.

    Can you provide guidance for getting that working please?

    Thanks!

    https://www.ads-software.com/plugins/be-subpages-widget/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    That’s strange, I just tried it on a blank WordPress installation and it is working just fine.

    The only thing I can think of is that code isn’t running for some reason. You might review your functions.php file to make sure there’s no errors above it. Or add it as its own plugin. In /wp-content/plugins, create a folder named “be-subpages-widget-alt-title”, and create a plugin.php file inside there with the following contents: https://gist.github.com/billerickson/828eac7646735acfc147

    Make sure you remove the code from your theme’s functions.php file so it isn’t being declared twice.

    Thread Starter jodamo5

    (@jodamo5)

    I found the problem … the alternative titles on subpages were working correctly, but I had an alternative title on the top level parent page, which shows as the widget title, and the above code doesn’t work for the widget title.

    Bill provided this additional code so that widget titles shows the alternative titles too. Again this goes in functions.php or a custom plugin file:

    /**
     * Alternative Title for Widget Title
     *
     */
    function be_subpages_widget_title( $title ) {
    	// Find top level page
    	$parents = array_reverse( get_ancestors( get_queried_object_id(), 'page' ) );
    	$parents[] = get_queried_object_id();
    	$parents = apply_filters( 'be_subpages_widget_parents', $parents );
    
    	// See if there's an alternative title
    	$alt = esc_attr( get_post_meta( $parents[0], 'be_alt_link_title', true ) );
    	if( $alt )
    		$title = $alt;
    
    	return $title;
    
    }
    add_filter( 'be_subpages_widget_title', 'be_subpages_widget_title' );

    Thanks Bill!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Documentation for be_subpages_page_title filter?’ is closed to new replies.