Support » Plugins and Hacks » [Resolved] Get Post Title for Category Name

[Resolved] Get Post Title for Category Name

  • I am using a contact form within a widget sidebar on both pages and also trying to get this work for a category page. Using the Dynamic Text Extention I used the following to get the title:

    “CF7_get_post_var key=’title'”

    However, this only works for posts/ pages and not category pages. Any idea how I can get this to pull the category name/ title into the dynamic field?



Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author sevenspark


    So the CF7_get_post_var shortcode specifically grabs Post variables. Since Categories aren’t Posts, the shortcode doesn’t apply.

    You’d need to create a custom shortcode that returned the current category name to do what you want. If you want to use the same shortcode for both, you’d need to detect the page type and then return the Post title or Category name depending on which page you’re on.

    Hope that helps,


    Hi Chris,

    Thank you for your reply.

    Can you give me any guidance on how I would create a custom shortcode that returns the current category name?

    Thanks in advance.

    Plugin Author sevenspark


    Hi Exponential,

    There are lots of great guides on writing shortcodes, which I recommend Googling and reading through.

    The current category name can be determined with get_the_category()

    Here’s a simple example to get the first Category:

    function my_category_shortcode(){
      global $post;
      $category = get_the_category( $post->ID );
      return $category[0]->cat_name;
    add_shortcode( 'my_category' , 'my_category_shortcode' );

    Hope that helps,


    Sorry to be a pain and thank you very much for you help!

    I have used your simple example within my functions.php file. The contact form is sitting in a widget area attached to the category pages.

    I have then set up a seperate CF7 form for category pages and am trying to create a dynamic text field picking up the custom shortcode I created.

    This is not working and I think I may have misunderstood some part of doing this:

    [dynamictext qual-cat id:qual-cat class:form-control ‘my_category’]

    any update on this..? Even i am facing similar issue.. Need to collect the category name.



    Forum Moderator

    If you require assistance then, as per the Forum Welcome, please post your own topic instead of tagging onto someone else’s topic.

    I am now closing this month old resolved topic as it references an older version of WordPress.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Get Post Title for Category Name’ is closed to new replies.