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
- How can i remove all html tags from get_the_content()?
- Is there a way to parse shortcodes in PHP?
- Display sorting options dropdown when using WooCommerce product category shortcode
- Retrieve multiple values passed to a single attribute in a shortcode
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- How to display multiple Post meta_key/meta_values by SQL query
- Export User Info to CSV from Front End
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Shortcode created to check language not works
- How to loop over custom fields in a page template?
- Add/echo div with Analytics-Code to function in functions.php
- How can I default to all WordPress roles when parameter is not included in shortcode?
- PHP contact form returns warning in text widget [closed]
- Recent post display using shortcode
- Need to turn this php into WP shortcode
- custom shortcode will not display the wrapped content
- Trigger popup in a php if/else statement
- Output Buffering – Everything between wp_head and wp_print_footer_scripts?
- How can I create a list of page titles from custom meta values?
- How to output a PHP file values by shortcode?
- Removing “wpautop” (auto tags) only on certain pages?
- Adding number to date not working [closed]
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Shortcode to show the code
- Multiple do_shortcode in page template
- $wpdb returns duplicate posts
- Shortcode to find and replace URL
- How to put a form with php code into a variable or shortcode?
- Shortcode to embed Edit Account form not working
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Split shortcodes to array of shortcodes
- PHP error with a shortcode: “no suitable wrapper” for file_get_contents
- How to make a conditional statement within $output in shortcodes.php?
- Define category ID using get_post_meta
- Remove Post if Advanced Custom Field is checked to fix paging
- Comparing Dates from custom field
- Display movies that apear this day next
- Problem in replacing the_content with the_excerpt()
- MySQL Query Returns Array () In Shortcode
- How to get woocommerce orders with get_posts method in a shortcode
- Counting number of posts in multiple (sub)categories using shortcode
- ACF relationship on user profile page used for allowed access
- Where does php code to load data go?
- How to return html as a string from php for WordPress
- Changing Date Format on Custom Meta Data w/shortcode call
- Add the shortcodes from the enfold theme to the other theme
- Offset with ajax load more posts duplicates
- How can i iterate through this shortcode array?
- Shortcode in a $output statement
- Need help with PHP functions
- When using shortcode, content stops generating after the_content
- PHP Shortcode – 500 error
- Run PHP Results inside WP Shortcode
- Sort by multiple options in custom field
- If or/and statement advanced custom fields [closed]
- On selecting shortcode generate selected shortcode table inside page editor worrdpress
- Top menu disapears in Category Pages when filtering using ACF
- How to echo a different field if another field is empty?
- PHP Puzzle: Unique Styles with PHP loop
- My title is showing after the shortcode
- HTTP 500 Error after Creating Shortcode
- Show button in header when product custom field is not empty
- Convert custom field date format to “WordPress default”
- “acf/load_field” Critical error upon saving/updating WooCommerce products [closed]
- Allow HTML in custom taxonomy description, and show it on front end