I thought of creating a shortcode to insert into the content of the
post, but while I can create one that includes just text, when I put
the above code into the shortcode.php file, it breaks.
Your code outputs data to the screen. You can’t do that with filters like the_content
. You need to concatenate a string and return it. Something like:
function the_content_cb($content) {
$str="";
if( get_field('kindle') ) {
$str .= '<a href="'.get_field('kindle').'"><img src="url.com"></a>';
}
if( get_field('nook') ) {
$str .= '<a href="'.get_field('nook').'"><img src="url.com"></a>';
}
return $content.$str;
}
Note: the_field()
is a plugin function– Advanced Custom Fields–, as is get_field()
.
Related Posts:
- Display all values of custom a field created with ACF on a page
- If Custom Field is empty don’t display div
- Unique key for each row in a repeater field
- How to Explode a Textarea Field and Echo each line separately, wrapped with HTML
- Importing hard coded custom field into acf field
- Showing content from one page on another
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- How to use thumbnail size of image if I’m only using src to get image
- Redirect to another page using contact form 7? [closed]
- Get URL from shortcode tag
- Advanced Custom Fields – display label and value only if value entered
- Only first shortcode gets executed
- Create a WordPress shortcode using PHP [duplicate]
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Creating an image from a custom field
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- Can ‘Custom Field’ data be inserted into this Short Code?
- Delete images from media library when user deletes an image from ACF Gallery
- Updating Metadata with Shortcode
- How to Create custom block for displaying information in content section which act like shortcode
- Block error message in foreach loop when looping through ACF field
- Query on a repeater date (acf)
- ACF – Can’t get custom post type by taxonomy
- Advanced Custom Forms PHP formatting for do_shortcode
- How to output values from a loop into a javascript array
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Custom fields changes the formatting of metabox input
- How can I put a custom field as the link of a button shortcode?
- Custom field within shortcode
- ACF Date fileds to Age Convert [closed]
- Shortcode Displays 2 times
- How to execute a shortcode within a custom field?
- ACF number less than comparison not working
- Cannot Access ACF Field Values via my Plugin
- How to create advanced custom fields for backend content
- Display posts in correct month order using single date custom field
- Display PHP within HTML values
- Custom profile field with birthday. Troubles with
- Showing a different gallery in a seperate post
- How to display posts by current user in a drop down
- Create own WordPress shortcode gallery
- WordPress – Display array data of a child
- ACF: how do I get the fields and its values of a specific group?
- Get value from shortcode to do something
- wordpress allow user to edit user profile with custom fields
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- How to display data from custom table in wordpress phpmyadmin
- Calculating a large number of MYSQL queries as customshort codes, slow
- Saving an array of dynamic repeater data as post_meta
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Need Help Fixing My Iframes [closed]
- Removing “wpautop” (auto tags) only on certain pages?
- Output ACF repeater on frontend user’s profile page (created with Ultimate Member) [closed]
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Firing schema via code in functions.php doesn’t work
- Colon is Missing In My Website Url in WordPress
- Remove the first 5 characters of the_title and orderby that
- Adding number to date not working [closed]
- Unread Repeater field IMG alt not working
- Unable to write multiple values back to ACF user field – PHP
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How can I add extra word in permalink when someone click download button?
- Update grandchild repeater field with value per row
- Saving and Restoring a Canvas on A Individual User Basis
- How to render a custom post type template with custom fields using shortcode
- Custom shortcode outputs plain text instead of HTML at top of post
- Seach custom post type posts only by meta fields?
- How to use wp_add_inline_style for custom CSS added via shortcode?
- Pass php dynamic variable to shortcode
- Slick + PHP + ACF + JQuery slide reveal not working
- How can I dynamically update the class in my shortcode?
- Creating own shortcode – echoeing php variable based on JS variable
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Run Shortcode of post’s custom field in functions.php / Plugin
- how to retrieve a value if a checkbox is checked
- Trouble checking if custom woocommerce checkout field is empty or not
- Two queries for a WP_User_Query search work perfectly apart, but not together
- How create a Shortcode with hover and complex options
- Remove from shortcode
- Displaying recent posts on static page with template-part via shortcode
- auto-populating custom nav with all items from custom post type
- wordpress 4.4 self hosted video (html5) doesn’t show
- do_shortcode with custom field
- Add / Update Custom Fields After Select Pictures in Media Window
- How to Reference/Echo Variable from Another PHP Function
- Remove echo from shortcode
- Replace shortcode in substring
- conditional logic for front-end custom field edits
- Trying to retrieve post meta
- Displaying custom field according to date
- Sort by page information by Ascending Numbers
- Automatic Shortcode Creation with Custom Fields [closed]
- Custom field values to taxonomy terms
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- Shortcode to show the code
- Shortcode returns values in the wrong order
- How to add specific meta tags to head of cart and checkout pages in woocommerce?
- Embedding PHP in shortcode $content