You can define your own custom functions in PHP just like you would in JavaScript. Here’s your code example rewritten using a function:
$page = get_page_by_title('Excerpts Showreel'); <-- This piece of code will change
// the code below will never change.
function get_my_content( $page ) {
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$title = $post_id['post_title'];
$content = $post_id['post_content'];
return $content;
}
echo get_my_content($page);
So long as you have your get_my_content()
function defined, you can use it anywhere you need to.
Related Posts:
- Using wp_add_inline_style without a stylesheet
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- Bestway To Define Theme and Plugin path and url
- Form to Add Posts to Custom Post Type
- How do I add settings to the Background Options Page?
- What is the right way to include a wp-admin file in your theme?
- WordPress twentytwenty theme inline css overriding css body
- What is the problem if I use CDN in my WordPress parent theme(built using bootstrap)?
- Active theme responds to theme change request to alert user
- LOST in WP Template Hireachy
- Theme showing incorrect update
- modify a output of a widget
- Enabling Default Widgets in a Custom Theme
- changing Specific section background image in wordpress
- Which is the simplest theme for WordPress to use it as your base?
- There’s an image named g.gif somewhere in my WordPress site
- How to highlight the current page in the nav menu?
- customizing the_password_form filter
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- Should I use language_attributes() or bloginfo(“language”) in html tag
- What’s the best action to use when you want to do something only once per theme setup?
- How to upload images using Settings API
- WordPress 404 page returning with default in IIS7
- searchform.php override not working
- How do I create a custom partial / template?
- Load child template based on parent
- How to make the_tags title translatable?
- Should I use include or load_template for including shortcodes, plugins and so on?
- Get a setting value conditionally in the Customizer api
- How should I be handling my theme version numbering?
- Set default featured image for terms of a custom taxonomy
- How would you accomplish the following advanced settings page?
- image url relative path not working in css file
- Timber: Get single image from media library with all attributes
- page.php dependent sites are not working in custom woocommerce theme
- Sort wp_query by sum of two meta fields
- How to i style the elements from the TinyMCE
- Integrate WooCommerce theme with a WordPress theme [closed]
- Why wp_nav_menu() doesnt show the proper meny when invoked two consecutive times?
- Change the “Default Avatar” admin option via functions.php
- ACF Pro make URL Linked in Custom Template [closed]
- How to escape multiple attribute at once in WordPress?
- Override plugin option by with a custom theme
- Can’t use admin_enqueue_scripts or wp_enqueue_script
- How is the `get_sidebar` function meant to be used to call a 2nd sidebar?
- Is WordPress a good option for this…?
- Review site using WordPress
- What happens if a theme is no longer supported?
- Running a function on post update with new post meta
- How to find and remove unnecessary theme scripts? [closed]
- Theme logo metadata into template file
- Is There A WordPress Hook for Accessing Attachments for A Particular Page?
- WP Customazation API doesn’t save the default Value
- Change WordPress Resource URL
- Setting conditional background image from meta value
- How to Emulate Default Navigation Menu Behaviour in a Custom Theme?
- Sample Theme Options page for Multisite – what to consider
- How to use shortcode inside of shortcode in theme
- Search Form Not Working
- My contact form – I’ve changed the source code but the changes are not being applied
- Theme calling page.php instead of home.php
- How can I run code in functions.php when switch_theme() is called?
- Why do sticky posts show in this menu?
- Dot “.” in option value foobars save options function
- Strict Folder and File Permissions for WordPress Themes Folder
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- How to properly use AWS SES for a contact form?
- No templates for condition page.php Elementor
- Default customizer colors aren’t displayed outside of the preview
- Use instead of for wp_nav_menu()
- Find out the reason that the Styles and scripts in the theme are loading properly in localhost but Not in server after deploying
- fetch all post from wp multisite network and sort all the post in descending order on the basis of “Created by ” term
- More HTML elements variety in visual editor
- How allow users to select the theme color?
- How to generate a rtl.css file for themes?
- How can i create my Onepage smoothscrool WordPress theme?
- What is the best practice workflow for new website overhaul and keeping current SEO ranking? [closed]
- hide/show a div in wordpress
- Add a customize control depending wich radio setting is checked
- Providing updates to your WordPress theme
- Create new sidebars trough admin post/page metabox
- How one category can have different fields?
- How to add script properly for certain post?
- How do child themes work?
- Why WordPress gets old templates code instead of the last updated ones
- Mutlisite in wordpress is not working
- How can i create a tag with the template’s name like below, and what is the purpose of using them? [duplicate]
- adding navigation to genesis themes
- Checking conditionals
- add_theme_page is not working
- including post-specific feed without full wp_head()
- Show post thumbnail only if it exists using timthumb
- How can I install my custom-made theme on a wordpress.com blog? [closed]
- IS there any reason not to include javascript in my own post’s embeds?
- How to create more templates to the same theme?
- How do I middle-align my header menu items in WordPress [closed]
- A problem in loading index.php
- How to add Dummy content when active wordpress theme without xml import?
- How to send async emails in wordpress?
- Is there any halfway decent documentation on the wp.media JS class?