• Resolved Demian

    (@demian85)


    Hi,

    Is there a shortcode integrated? This would be a simple straight forward approach.

    Demian

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

    (@mrwweb)

    @demian85 Can you say more about how you’d use a shortcode?

    This is 100% untested, but this might work (in functions.php or an mu-plugin) if you place the shortcode in a template that is on a post type archive screen:

    add_shortcode( 'ptad_description', 'ptad_get_post_type_description' );

    You’d then use [ptad_description] where you want the description.

    Use at your own risk, and make sure you know how to remove the code if you try it out.

    Thread Starter Demian

    (@demian85)

    Hi @mrwweb

    Thanks for the quick reply. We have around 8 different CPTs, they use an archive template and I would like to return that post type description into the template.

    I am comfortable with coding, so no worries. However, the approach for the short code does not return anything unfortunately.

    Plugin Author mrwweb

    (@mrwweb)

    @demian85 If you have access to the template, then you shouldn’t need a shortcode. Putting the_archive_description() into your template should show the description. If not, then there’s probably an issue with the theme or a plugin messing up the page’s query so that function doesn’t work.

    Thread Starter Demian

    (@demian85)

    Hi!

    I notice you work from the point of view to build pages based on its php template files. But 90% of the wordpress sites are using frontend page builders like wpbakery, elementor or gutenberg. So a shortcode should just also work there. If you have a prof. Theme, amending archive.php is not part of wordpress anymore unfortunately 😉

    • This reply was modified 1 month, 3 weeks ago by Demian.
    Thread Starter Demian

    (@demian85)

    To give an example. We use the CPT UI plugin to generate post types. They also have a field for post type descriptions, unfortunately not a user friendly input field. But if I use a custom function to project it into the frontend template it works:

    function custom_output_cpt_description_shortcode() {

        echo get_the_post_type_description();

    }
    add_shortcode( 'post_type_description', 'custom_output_cpt_description_shortcode' );
    Thread Starter Demian

    (@demian85)

    It seems that $post_type returns into an empty string from the plugin. I also get this warning:

    PHP Warning: array_key_exists(): The first argument should be either a string or an integer in /wp-content/plugins/post-type-archive-descriptions/inc/template-tags.php on line 36

    Not sure if $post_type is properly defined.

    Plugin Author mrwweb

    (@mrwweb)

    We use the CPT UI plugin to generate post types. They also have a field for post type descriptions, unfortunately not a user friendly input field. But if I use a custom function to project it into the frontend template it works

    It sounds like there may be some confusion around how this plugin works. This does not display the description attribute of the post_type object, but rather creates a custom setting and editor for writing a description for each post type. You can see that editor and menu location in the plugin’s screenshots.

    If you use either the_archive_description or get_the_archive_description in your template, then the plugin filters the result and displays the custom description you’ve edited.

     echo get_the_post_type_description();

    Note that shortcode functions should always return their contents and not echo it.

    PHP Warning: array_key_exists(): The first argument should be either a string or an integer

    I tested that shortcode and it didn’t work. This was the error that resulted. This works instead:

    add_shortcode( 'archive_description', 'get_the_archive_description' );

    I notice you work from the point of view to build pages based on its php template files. But 90% of the wordpress sites are using frontend page builders like wpbakery, elementor or gutenberg. So a shortcode should just also work there. If you have a prof. Theme, amending archive.php is not part of wordpress anymore unfortunately

    This will work on any theme that supports the built-in archive description function that’s core to WordPress.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.