Contact Form 7 Dynamic Text Extension
[resolved] [closed] Get Post Title for Category Name (7 posts)

  1. Exponential
    Posted 2 years ago #

    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?



  2. sevenspark
    Plugin Author

    Posted 2 years ago #

    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,


  3. Exponential
    Posted 2 years ago #

    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.

  4. sevenspark
    Plugin Author

    Posted 2 years ago #

    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,


  5. Exponential
    Posted 2 years ago #

    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']

  6. jayaram5837
    Posted 2 years ago #

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

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7 Dynamic Text Extension
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.