First, i'd like to point I do this probably wrong, but this is a bit of a desperate thing and it popped in my head.

We are developing a site for a client, and he wants breadcrumbs. Now we downloaded a plugin that allows you to place breadcrumbs by calling the breadcrumbs_trial function. Since the theme doesn't support PHP additions, and we want to place it a dynamic spot within the page that isnt accessable easily.

Since the theme codeblock accepts shortcode, i thought (maybe stupid) to create run the breadcrumb in a shortcode, so I made an attempt,

function breadcrumbs_func( $atts ){
add_shortcode( 'breadcrumbs', 'breadcrumbs_func' );

Now I realise, I go offcourse in the scope of the function, and the breadcrumb_trail() function isn't defined in here. Is there a way i can run this stand alone function from another plugin in such thing?


I made a typo, and it does run, but it just isn't displayed at the right position now... tweaking further i guess

  • the reason it is not displayed at the right location is possibly that the function prints the result instead of returning it as it would be necessary in a shortcode. – Michael Nov 11 '16 at 19:59

This will probably not work, or work in unexpected way. Shortcodes should probably be displayed only on a "post" single page. Using a shortcode in the way you want will either make the breadcrumbs not to be displayed on archive pages or have them displayed there multiple times or wrong places.

What you should do is a minimal modification to the theme. Insert a do_action('show_bc); at the appropriate place in the header file ("fork" it in a child theme if you use one). Then add something like add_action('show_bc','breadcrumb_trail'); in the theme's functions.php or in a plugin.

As for the exact problem you have in your code, it is because shortcode handlers are supposed to return HTML, and not to output it. If the BC function do not have an option to return the HTML instead of echo-ing, you will have to do output buffering around its call.

  • Thanks for the input. I ll have to look arround see if something else is available to use. – Dorvalla Nov 11 '16 at 13:43

That is very tricky. I would manually place it in the template directly where I want it (or where the client wants it) using:

<?php echo do_shortcode('[some-shotcode]'); ?>  

But then again, that is just me. If you rely on the WYSIWYG content box, you will end up with undesired results – possibly.

  • thanks for the input. My point is that it has to be displayed under an element in the_content. Hence I have to rely on the WYSIWYG editor. That was also the main reason why I wrote this shortcode. If I could just simply add php in the theme itself on a page in a code block, this would haven't been an issue – Dorvalla Nov 11 '16 at 13:42

you could try this:

 add_filter( 'the_content', 'customcode_after_content' ); 

 function customcode_after_content( $content ) { 
    if ( is_singular('post') {
        $extracode = '<p>hi</p>';

        $content = $extracode . $content;


    return $content;

then you could input either a shortcode or just the actual code. Wouldn't have to mess with header either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.