How about this?
For PHP 8 (faster)
if ( str_contains( get_post_field( 'post_name' ), 'activity') ) {
get_template_part( 'activity' );
}
For older versions of PHP
if ( strpos(get_post_field( 'post_name' ), 'activity') !== false ) {
get_template_part( 'activity' );
}
Related Posts:
- Slugs as breadcrumbs for Pages
- is_account_page() change to page slug
- Why isn’t is_page working when I put it in the functions.php file?
- Get the ID of the page a menu item links to?
- Disable visual editor on one specific page
- How can I programmatically create “child” pages on theme activation?
- How to display error messages using WP_Error class?
- which is the function that removes accented vowels?
- Check if has any sidebar active on current page
- Remove Page Title from Static Frontpage
- Target a certain page within wordpress backend (admin) i.e. Pages > About
- Breadcrumb how i can display page title with parent > child title with permalink ? any Idea
- Pages should have priority when using add_rewrite_rule
- Enqueuing Script in functions.php vs on the page
- Programmatically set page template based on page ID
- Get page slug and assign a variable within functions.php
- Delete pages and Create default pages for all new network sites
- how to change link of some wordpress pages
- Make menu structure match page heirarchy on page parent change
- Change the slug of a particular page every x hours
- wp_insert_posts keeps adding multiple pages
- Sanitize slug title
- How to include local menu based on page id?
- Batch update menu_order attribute alphabetically
- Identical custom taxonomy slugs for same hierarchical children
- Don’t delete a page if it holds users
- List all-childpages on parent-page AND list child-pages on childpage itself but not the current one?
- Display post shortcode content in the sidebar?
- Why is my page feed returning empty content?
- Function only on a specific page
- Functions For Calling Specific Elements
- Get page id or status by private pages?
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Use /prefix/postname as a slug in post_name?
- Enqueue script on every page except one
- Get term slug by term id and then explode it
- How to store a number (coming from cookie) into query vars for later usage in other filters?
- How do I register a new settings page? [closed]
- Only echo Page Content (not page title & page content together)
- get content from page through AJAX
- How Can I Create a Friendly Slug for a Dynamic Page?
- Remove the delete link from pages without a plugin
- Display list of pages that contain a certain string within the slug
- Change is_front_page() to is_page() to display ‘hero’ on entire site?
- Get child-pages slugs of current page into js-file
- Define an extra field for all pages (with no plugin?)
- Custom field not updating via functions upon publishing
- Using array page name together with page id to deregister script
- How to add a class name to the ancestor of a post?
- How to add an excerpt and read more link to a page?
- My website is generating weired url parameters of paginated pages
- custom function works on page.php template but not in functions.php
- Override categories with Pages (block theme)
- Upload Multiple Files With media_handle_upload
- Add custom template page programmatically
- What is the difference between get_page_link and get_permalink functions?
- Woocommerce add to simple product attribute programmatically [closed]
- mysql custom wp query
- TinyMCE custom stylesheets for different post types
- Order get_users() by last login date. Is it possible?
- Display random text from a file with the WP built-in AJAX API
- Function to Download External Images to My Site
- How to call a function on particular page like ‘contact-us’ from function.php of child theme
- Detect Safari desktop browser and include the detection in a shortcode
- Is It wrong to use oop approach on functions.php?
- How to preserve edits to Name or Slug of term when using wp_update_term on save?
- Where do I add html code to the menu div?
- Add function to every post?
- Understanding and altering the structure of posted images
- Allow Post Author to be 0 on Update
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- Trouble with adding a wp_enqueue_script on wordpress
- Display ‘BuddyPress Follow’ follow button to non-logged in users [closed]
- Post meta not updating
- Why doesn’t is_page(id) work in functions.php?
- Function to alphabetically sort custom post types creating duplicates
- get_post_meta() problem again
- How to parse a shortcode within a shortcode?
- Variables not showing in short code
- Prevent loading of functions
- loginout function customization
- Add Login and logout buttons to top menu bar
- implementing a centralized content “show-do-not-show” toggle?
- Override a Post’s URL with Advanced Custom Fields Function
- Passing function arguments via a shortcode
- Widget is displayed in two places
- Link to an externally created photo albums
- How to identify author in wordpress comments?
- Why does Featured Images not load in the backed?
- Help! Need a different logo on my main page from my other pages
- RSS feed including post updates
- WordPress not showing pagination links
- Automatically add tag if a checkbox is checked
- How to add a meta information to the URL?
- How to assign a div class to a echo function [closed]
- Getting error on function.php
- delete_term is not working properly with add_action()
- Add URL parameter to nav links based on domain
- hide div if empty
- How to display a function inside shortcode tags