• Resolved tim_marston

    (@tim_marston)


    Hello

    On our website, we not only use the standard WP posts, but we also have four custom type posts for our content.

    Because the tables do not pull through to the custom post types, I would like to register the shortcode in our custom theme functions file.

    I noticed and read in your documentation on your own site where you have the query instructions to add to the theme files. That would work, but our problem is if we use that method of output, the chart would have to fall in the same place in every custom post. The line would be dictated by where I place it in the theme file.

    I would prefer to register the shortcode in functions.php so that it would work in the custom theme wherever we choose to put the shortcode in the content.

    Also, the shortcode needs to output the correct table, as every post would have a different table.

    Could you please help in letting me know which “add shortcode” to put in the theme’s function.php.

    Thank you so much

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    You shouldn’t actually need any special handling regarding Shortcodes in your CPT posts. All that normally is required is proper usage of the the_content(); template tag in your theme, inside the WordPress “Loop” that loads your posts. Are you maybe using something like $post->post_content; there to echo the post content?

    Regards,
    Tobias

    Thread Starter tim_marston

    (@tim_marston)

    When we put this in the theme file, the table outputs perfectly

    echo do_shortcode(“[table id=2 /]”);

    But when we use the actual shortcode in the custom post

    [table id=2 /]

    We get only the shortcode and not the table.

    All of the commands in the theme file start with “echo”.

    The content seems to be called up like this

    get_template_part( ‘template-parts/content’, ‘howtopost’ );

    and later, it when the php ends, it does say “end of loop”

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    ok, this means the relevant code should be in a file “template-parts/content” or similar in your theme. Can you maybe check that? It needs to have a call for the_content().

    Regards,
    Tobias

    Thread Starter tim_marston

    (@tim_marston)

    I hope this is the part you are looking for. And thanks again for trying to help with this. Your support on the plugin is phenomenal.

    <?php
    if ( ( is_singular() || ‘content’ == $bavotasan_theme_options[‘excerpt_content’] ) && ‘main’ == $mb_content_area && ! is_archive() && ! is_search() ) {
    the_content( __( ‘Read more →’, ‘magazine-basic’ ) );
    } else {

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    this looks ok to me. Shortcodes should be evaluated with this…

    Unfortunately, I’m out of ideas here then. Can you maybe try again after temporarily deactivating all other plugins and after switching to a WordPress default theme like Twenty Twenty? That way, we can find out if something is interfering.

    Regards,
    Tobias

    Thread Starter tim_marston

    (@tim_marston)

    Hey man, sorry for the late reply, we found a work around. Thanks for your amazing support

    Plugin Author TobiasBg

    (@tobiasbg)

    Hi,

    great! That’s good to hear ??

    Best wishes,
    Tobias

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Register Shortcode in Functions for Custom Posts’ is closed to new replies.