Forum Replies Created

Viewing 15 replies - 121 through 135 (of 2,399 total)
  • Plugin Author John Havlik

    (@mtekk)

    You shouldn’t add a field for post-your_post_type. In my example code, you have to replace post-your_post_type with post-page if you want to target the page post type (if you want to target a different post type, you will need to replace the your_post_type with the post type name. The following code makes this replacement and should work:

    add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title', 3, 10);
    
    function my_breadcrumb_title($title, $type, $id)
    {
        if(in_array('post-page', $type) && get_post_meta($id, 'last_breadcrumb_title', true)) {
            $title = get_post_meta($id, 'last_breadcrumb_title', true)
        }
    
        return $title;
    }
    Plugin Author John Havlik

    (@mtekk)

    Breadcrumb NavXT includes a widget and a Gutenberg block for when you don’t want to call the bcn_display() function via PHP in your theme. There isn’t a shortcode included with the core Breadcrumb NavXT plugin (there is an extension that adds one). As for specific Elementor support, as a general philosophy, Breadcrumb NavXT does not add support for 3rd party plugins/themes/code within the core plugin. I do not have experience with Elementor, I’m not sure how it actually works and what it does for integrating other plugin elements. If it supports widgets or blocks, then I would think you could use the Breadcrumb NavXT widget or Gutenberg block.

    Plugin Author John Havlik

    (@mtekk)

    Normally, the home breadcrumb should be linked, as long as you’re not on the home page, especially when using the default settings for the breadcrumb templates. Assuming the template is correct, my guess is there is code hooking into the bcn_breadcrumb_linked filter and returning false for the home breadcrumb. If the home breadcrumb seems to use the unlinked breadcrumb template, this may be the case. Otherwise, there may be something else unique about your setup which is throwing Breadcrumb NavXT off/making it think that the home breadcrumb should never be linked for some reason.

    Plugin Author John Havlik

    (@mtekk)

    Can you provide an example, similar to the pre-7.2 screenshot for what it getting generated after upgrading to 7.2? Also, what version did you upgrade from? In the 7.1 to 7.2 transition, the only custom post type changes were for if there was for the setting initialization and the settings page only WP_Post_Type objects are considered to be valid members of the $wp_post_types global.

    Plugin Author John Havlik

    (@mtekk)

    In this case, you want to replace post-your_post_type with post-page since you’re using the page post type. The in_array() function is a PHP function, not a WordPress function, so it doesn’t understand the post_type=page argument format.

    Plugin Author John Havlik

    (@mtekk)

    I recommend using the code example I provided instead of the code you’re currently using. It will not have the PHP warning like your code does as it doesn’t use the $id until the case where it should be valid (i.e. that the breadcrumb is for a post). The only change that my example code needs is replacing the your_post_type in post-your_post_type with the post type you want to target (or replace it with post to target all post types).

    Plugin Author John Havlik

    (@mtekk)

    Is “Best Bar Asia” a post or a term?

    A point of clarification, bcn_breadcrumb_title operates on every breadcrumb in the trail. You have to within it check for the specific type of breadcrumb you’d like to modify the title for. It is not specifically operating on the last breadcrumb in the trail.

    I’m not exactly sure where you found the code you started with for the filter, but it looks similar to something recently posted to the support forums which had a couple of similar issues. You only want to return $tittle rather than trying to return all three parameters that are passed into the filter (the second two returns are literally doing nothing so they shouldn’t be there). Additionally, using get_post() within this filter is not necessarily safe/not guaranteed to yield the desired results, instead you want to use the information passed into the filter (the $type array and the $id). An example is presented below:

    add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title', 3, 10);
    
    function my_breadcrumb_title($title, $type, $id)
    {
        if(in_array('post-your_post_type', $type) && get_post_meta($id, 'last_breadcrumb_title', true)) {
            $title = get_post_meta($id, 'last_breadcrumb_title', true)
        }
    
        return $title;
    }

    However, this code is only going to target posts. If “Best Bar Asia” is a term, then you will need to use get_term_meta() instead of get_post_meta() for that one. And, in the code above, you will want to check for ‘tax-your_taxonomy_type’ instead of ‘post-your_post_type’ where your_taxonomy_type or your_post_type is the taxonomy or post type you’re wanting to try to get the meta for. An example of code that would do both:

    add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title', 3, 10);
    
    function my_breadcrumb_title($title, $type, $id)
    {
        //Handle posts of type your_post_type
        if(in_array('post-your_post_type', $type) && get_post_meta($id, 'last_breadcrumb_title', true)) {
            $title = get_post_meta($id, 'last_breadcrumb_title', true)
        }
        //Handle terms of taxonomy your_taxonomy
        if(in_array('tax-your_taxonomy', $type) && get_term_meta($id, 'last_breadcrumb_title', true)) {
            $title = get_term_meta($id, 'last_breadcrumb_title', true)
        }
        return $title;
    }

    Lastly, if you really don’t want to go through with the write code to do all of this path, the Title Trixx extension (premium) provides the metaboxes for both posts and terms (of any type) to allow you to override what is used for the breadcrumb title.

    Plugin Author John Havlik

    (@mtekk)

    Can you elaborate on what you’re trying to do (provide more detail and/or an example)? Within taxonomies themselves, there isn’t really a concept of having a selectable hierarchy; either terms have parent terms or they don’t. So, I’m unsure of what you are trying to do and hope that further detail and/or an example helps.

    Plugin Author John Havlik

    (@mtekk)

    bcn_breadcrumb_title is the correct filter to use. However, you filter function has some problems with it that are worth discussing.

    First, it should just have one return, return $title;. Since PHP executes in order, the behavior will be the same as what you currently have (it will return right away so the second 2 returns never get executed). For WordPress filters with multiple parameters, only the first is the item to be filtered (and the one you need to return), the others provide context for the filter.

    I don’t think the conditions within your if statement are going to yield what you want. It would be better to check the $type array for the post type you care about, and then make your call to get_field. In fact, I would not call get_the_ID() either. If you want this to only apply when the breadcrumb is for the current item (not sure if that is the intent), you can check the $type array for 'current_item' being a member. This really is only necessary if the post type is hierarchical as for non-hierarchical post types aren’t going to have children (so a breadcrumb for said posts will always be the current item).

    It appears get_field is not a WordPress function, the best practice is to check for its existence before calling (to prevent PHP errors if the plugin providing that function isn’t present for some reason).

    With these changes, you code would look more like the following:

    add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title', 3, 10);
    
    function my_breadcrumb_title($title, $type, $id)
    {
        if(in_array('your_cpt', $type) && function_exists('get_field')) {
            $title = get_field('your_meta_tax', $id);
        }
    
        return $title;
    }
    Plugin Author John Havlik

    (@mtekk)

    Generally speaking, you should display the entire hierarchy when using hierarchical taxonomies (in general, if you want to hide a term, that term probably should be of a different taxonomy). That said, you can use the bcn_after_fill action to loop through the breadcrumbs and remove the one for the term you don’t want to have appear. If you don’t want to write code to do this, the uManager extension provides two GUI methods of doing this (via the admin bar and via the term editor).

    Plugin Author John Havlik

    (@mtekk)

    As a follow up, Breadcrumb NavXT 7.2 was released yesterday and should fix PHP 8.1 compatibility issues present in the previous versions. Please let me know if you are still experiencing issues with PHP 8.1.

    Plugin Author John Havlik

    (@mtekk)

    Breadcrumb NavXT allows you to select any of the ‘public’ taxonomies that are registered for a post type (other than the page post type) for the post hierarchy within the Breadcrumb NavXT settings page in the WordPress admin. Settings for post types are under the “Post Types” tab. Look for the “Hierarchy” setting for the post type in question, and you should see a listing of all of the ‘public’ taxonomies registered for that post type. Select the taxonomy you wish to use, and then press the “Save Changes” button at the bottom of the screen. Breadcrumb NavXT should then use the updated hierarchy for breadcrumb trails generated for the posts of the post type in question.

    Plugin Author John Havlik

    (@mtekk)

    From looking at the code, my assumption is wp_kses_allowed_html() is returning something other than an array on your site. This may be due to something hooking into one of the several filters within that function and not returning an array like it should. You could try deactivating all plugins other than Breadcrumb NavXT to see if the warnings go away. What page/where do these PHP warnings end up showing up, is it on the front end of the site, on the Breadcrumb NavXT settings page, only on the plugins page immediately after activating, or somewhere else?

    Plugin Author John Havlik

    (@mtekk)

    Using the slugs instead of the post title for the title Breadcrumb NavXT uses isn’t something that the core plugin will do. That said, you could make it do that in a variety of ways. One way would be to add a custom template tag for %slug% and replace that with the slug using the bcn_template_tags filter (see https://mtekk.us/archives/guides/how-to-add-a-custom-breadcrumb-template-tag/ for an example on using this filter). Another option would be hooking into the bcn_breadcrumb_title filter and replacing the normal title with the slug, on-the-fly for the applicable items. Lastly, if you don’t want to write code to accomplish this, the Title Trixx extension allows you to set custom titles for posts (of any post type) and terms via a meta box in the post and term editors, and this extension has an ‘import slugs as breadcrumb titles’ feature.

    Plugin Author John Havlik

    (@mtekk)

    The current development version (on GitHub) has PHP8.1 support fixed. Hopefully, within the next couple of weeks I will be able to get the next release (7.2) out which will include this fix.

Viewing 15 replies - 121 through 135 (of 2,399 total)