I’d suggest doing it this way to avoid running into problems where you split within a sentence/paragraph.
Try splitting on <p>
– then put the first element (first paragraph) into <div class="content-first-half">
and the rest (if any) into <div class="content-second-half">
in your template.
It should be something like this (assuming $content
has the html for the post)
$paragraphs = preg_split('/<p/i', $content);
array_shift($paragraphs); // ( remove first empty element
$first_half="<p" . array_shift($paragraphs);
$second_half="<p" . implode('<p', $paragraphs);
I chose <p
to split on since presumably the content will be formatted into paragraphis with <p>
tags – but could have inline styles/classes attached, so you can’t split on a <p>
.
As far as getting the post’s custom field, this should be a good start.
Related Posts:
- How can I add dropdown widget/box to admin post page?
- Custom post type loops with different page templates
- Limit Authors to their Own Posts on front-end excluding admins
- redirect after submiting post for review
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Featured image in custom post is being disabled
- Why isn’t my custom post type using the corresponding custom post template?
- Display a query with multiple post types and same relationship on a single page
- previous_post_link() and next_post_link() with a custom post type?
- Setting a custom sub-path for blog without using pages?
- Multiple Content Block
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- How do you output custom code between posts in the loop?
- is_page_template not working as expected
- I am having a problem with form updating/editing WordPress post on the frontend
- Output custom post shortcode. Help spot the error.
- WP_Query is printing out only one post when posts_per_page is set to multiple
- Loading all files within a directory
- Blog page showing same content as homepage
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- What’s the difference between same wp functions get_posts(); functions in different form?
- How to customize a permalink (URL) structure?
- Can I list a custom post type within another custom post type in the admin area?
- I would like to have different styles for my posts based on the content of each post
- Set URL link to featured image of custom post type
- AJAX load more for different custom post type loops
- On update or create post redirect to current post position in list
- get_post_meta not working on publishing
- Redirect 404 page with ID in slug to associated page with same ID in slug
- WordPress wrapped added a span tag to every single p tag
- ACF field key/value to show on taxonomy list
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Allow users to create posts without logging in?
- Configuring a meta query with multiple post types that have the same relationship on a single page
- How to assign classes to all elements?
- Different Category system needed for the Custom Post Type
- Redirect to another page using contact form 7? [closed]
- Meta-Boxes for CustomPostType cause PHP Errors and Notices in “Add New” view
- categories should be available across all custom post types
- Loop increase number
- Assign category a default post type
- Showing custom post type categories in the menu
- How to use a variable as a function name?
- Creating separate feeds for custom post types
- Removing full title and breadcrumb header container for a specific post type
- Show current user posts in custom post type query
- Custom Ratings for Theme, Proper way to Refactor Code and Clean up Template File
- Get post format
- How to add new post using a form to categories when categories are using as menu
- How to set the mainpage of a custom post type?
- Using Wp_Query, Json to add Highcharts series data
- Send post changes to set email addresses (not users or subscribers)
- Let users upload image(s) to the post from front end
- Foreach loop returning more than one item when querying taxonomy
- Function to erase every post from a taxonomy
- Display author box on just certain category posts?
- Post type Echo code is repeating on homepage
- Function to allow single post template based on custom taxonomy?
- Is it possible to get the specific content on the search page?
- php dynamic content inside shortcode
- How to change Elementor Template for Single Page Post on Load
- update custom taxonomy custom fields
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- Check that a slug is present in the get_terms request
- open custom post type in popup window instead of page
- Assigning categories to custom post types via a front-end form; only works for native post type
- WordPress – display relationship between blog posts and custom posts
- Post template not applying on theme (potentially rendering as Page template)
- Load info from customposttype into template page
- wp_post_delete is deleting all offices
- Persist meta box choices throughout all posts of same post type
- Change Search display for Custom Post Type
- subtracting the current post form then whole loop, which is generating all CPT titles
- How to assign post to category
- Assign for all post of a post type a specific single-post template
- Custom Post By Category
- Stored meta from attachment, video length?
- How to get the posts that my following users are liked?
- Duplicate posts in my custom loop
- When post is Published, insert into custom table a number – custom post type
- How to mark posts as visited
- Getting a 404 on single custom post type page when using rewrite on a custom taxonomy
- can’t see categories in appearance-menu-categories
- Function not pulling image or text from custom post type
- Custom Loop for custom post type. Compare by meta_value?
- Add HTML before a specific div?
- How to make a template for a specific post of a custom post type?
- How to hide home title on pages and posts?
- Apply text based styling done for a single post in WPBakery to all posts / create a template out of it [closed]
- How to string lines from the_content() hook in WordPress?
- PHP Button Custom link [closed]
- Custom Post Types using wrong template (index) instead of archive-{type}.php – previously worked as expected
- How to I add count of custom posts listed in a post as a prefix to its title
- How to make a non-public post on wordpress approval?
- Custom post type is_singular condtional not working when managing sidebar display
- how to display custom taxonomies in front page
- How do loop categories post from according in WordPress? is it impossible to solve this problem?