1) Yes, there’s better ways…one would be to use a shortcode instead of storing php in your db. Write and register a shortcode callback that reads your file and returns the content and replace your <?php ... ?>
section in the post with the shortcode. Also, you can read the file with file_get_contents();
, saves you a few lines of code.
2) You could write a function that simulates that, but the benefit would be too minimal to justify the effort.
BUT: Instead of hardcoding your file path into the shortcode, you can get its path via get_attached_file($attachment_id)
.
Related Posts:
- Adding content to archive and taxonomy pages on custom post types?
- Order by & include array by specific post ids
- Add Content to Page without shortcodes
- Show certain terms from custom taxonomy but exclude ‘parent’ terms?
- Include multiple custom post types [closed]
- Custon Content within WordPress Loop
- writing posts in indian regional language (Punjabi)
- displaying content of custom post type
- Custom post type name and assigning custom taxonomy
- Custom meta box includes
- Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?
- How to get the posts of a custom taxonomy term
- Why are the comments disabled by default on my custom_post_types?
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- Custom Post Type menu name
- Get Custom post with ID
- Is it OK to move admin menu items?
- Adding %author% in custom post type URL structure?
- Syntax to get the Nth item in a list of custom post types?
- Filter by custom Field for Custom post type Admin Listing
- Problem excluding category from get_next_post
- remove support for ‘Categories’ for a custom post type
- Display different gutenberg template from selected post attributes
- Recent comments on author page?
- How to show posts from multiple post types in a single loop? And display them separately on the same template
- WordPress custom post type Single.php?
- WordPress is executing URL in code when called via wp_mail()
- Automatically Add a Category to a Custom Post Type
- Detect if 1st, 2nd or 3rd level custom page?
- Show Custom Post Type values in WordPress grid view
- WordPress tax_input only if logged in
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- CPT in Posts tab instead of its own tab
- Custom Post Types and archives
- Add 32×32 icon to custom post type index page
- Loop that displays the first post of every available custom post type?
- How do I prefix blog post urls as mysite.com/blog/%postname%/ but allow authors to still be located at mysite.com/authors/%nicename%?
- get_template_part() – post-meta not working?
- How can I display custom post types under multiple views?
- Automaticly add slug to posts
- Filtering by Post Meta Custom Fields – Performance
- Custom post type, permalinks & pagination, going wrong
- In WordPress how do you create a custom post type with the author’s name in the slug?
- Filter post by current 2 differents users id
- get_the_terms return only last term
- Query custom post type only if it contains another custom post type
- Custom template with CPT doesn’t display on frontend
- How do I get array of types associated with a taxonomy?
- Custom template page with custom archives listing by user
- Unable to get post archive link
- How to call in Custom Post-Type Categories?
- Child post with numeric only slug keeps redirecting to parent
- creat filter with wp_query
- Are pages consuming more server resources than posts?
- Possible to add different google analytics in custom post type?
- Portfolio Page for Classic Posts
- next/previous links on custom post single a little screwy
- Archive for a Taxonomy of a Custom Post type
- Including all post id’s of a custom post type into an array
- Dump custom post type database
- Create a custom post type for a photo post
- Linking to Post Types from wp-admin
- Custom post type Shortcodes wordpress
- custom hierarchical taxonomy and custom post type list contains surplus posts
- Show category and tag link as a submenu under custom post type submenu
- Display custom meta on page that has been check in custom post type
- Custom Post Type Archive template not being called
- How to selected value default in option list?
- Automatically add a character to field in edit post page
- Add the custom post term to the custom post title
- Display 3 recent posts from one taxonomy
- Query for bbPress replies to current topic?
- Custom post type and multi taxonomies + customize url
- Grouping custom wordpress post types by acf value
- Get_post_custom not fetching value from array wordpress
- Archive Post Not Showing All Post
- Get an array of the number of post per year of a custom post type (WordPress)
- WordPress Post ID overwritten when I create a new post?
- Private:Autodraft post created automatically, Is that normal?
- Custom taxonomy with custom post type template not showing
- Loop to display parent categories in custom taxonomy
- pagination for a custom query
- Custom nav menu current item custom link problem
- Use Tags to Query Associated Multiple Posts and Get The Average Of Custom Field Values
- redirect old post type url to new structure url
- Custom Post Type + Category archive
- one get_posts to return a number of custom posts for each meta value
- custom_post_type with umlaut in name
- $wpdb returns no results with SELECT query on custom post type, works on default post type
- current_page_item and custom post type?
- How do I do this?: If custom post type exists, echo it, else do not
- WordPress custom post type post and category links 404
- Get Posts From A Certain Post Type In An ID Array
- Custom post type efficiency
- One set of categories for multiple custom posts
- sidebar hierarchical menu category & custom post type
- Choose custom post type template by category
- Query order by meta value force specific tag first
- Custom post type is_singular condtional not working when managing sidebar display
- Is it possible to specify a time interval (from, to) in ACF with date picker, or other custom field?