WordPress.org

Ready to get started?Download WordPress

Forums

Adding a custom field inside shortcode in my page template (7 posts)

  1. roosterink
    Member
    Posted 2 years ago #

    Hello, I am trying to add a custom field to my page template, but I am trying to insert it in between some existing shortcodes from a plugin. My end goal is to have tabs (which are being placed in my template by shortcodes) and have my client be able to select a custom field to add content to each of the tabs. Here is the code I added to my page.php template

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Is there anyway to do this?

  2. roosterink
    Member
    Posted 2 years ago #

    Here is the code

    <?php echo do_shortcode('[wptabs]
      [wptabtitle]News[/wptabtitle]
        [wptabcontent]<?php echo get_post_meta($post->ID, 'fieldtext', true); ?> [/wptabcontent]
      [wptabtitle]Stats[/wptabtitle]
        [wptabcontent] Contents of the Quotes tab [/wptabcontent]
      [wptabtitle]Pedigree[/wptabtitle]
        [wptabcontent] Contents of the Tables tab [/wptabcontent]
    
    [/wptabs]'); ?>
  3. Quin
    Member
    Posted 2 years ago #

    Wait, you're adding PHP to a WordPress page?

  4. Ervald
    Member
    Posted 2 years ago #

    Isn't it better if you used extra arguments for your shortcodes?

    And then use it like this:

    ex.

    <div class='wptabs'>
    [wptab title='News']content[/wptab]
    [wptab title='Stats']content[/wptab]
    [wptab title='Pedigree']content[/wptab]
    </div>

    I don't see why you have to use Shortcodes to do this though...

  5. roosterink
    Member
    Posted 2 years ago #

    Well the shortcodes enable the tab plugin I am using to work, just adding the div tags to the page.php does not enable the tabs. I have to use the php echo do_shortcode to make them work. My end goal is to have a page template my friend can select and then the tabs are automatically on the page, but I want him to be able to use custom fields to add the content for each tab, since I will not be adding it and he is not able to hand code them. Does that make since?

  6. Ervald
    Member
    Posted 2 years ago #

    Can you show us the code how the tab plugin shortcode is being generated?

    Search for this add_shortcode in your tab plugin's folder and it's function.

  7. Stefan83
    Member
    Posted 1 year ago #

    Did you ever get this to work? Its exactly what I'm looking for..

Topic Closed

This topic has been closed to new replies.

About this Topic