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)
- How to Programmatically Replace Characters in WooCommerce Product Slugs?
- Help with IF has focus then… statment
- Changing the text of Upload/Insert on Posts and Pages Screen
- How to change a specific admin label
- How d0 i get the number of attachments in the post
- struggling with syntax for the_post_thumbnail();
- Adding a pagenavi to function for displaying bookmarks
- include w_thumbnail_src in function?
- implementing a centralized content “show-do-not-show” toggle?
- Multiple, Dynamic, Sidebars Problem – First Sidebar not working properly
- A better way to get stats
- Looking for Functions File that doesn’t Exist
- hook for dashboard show_user_profile
- How to add a shortcode to call a function
- How can I call a PHP function inside a hardcoded shortcode?
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- WordPress comment_form() does not display actual comments
- Any adverse effects of adding apply_filters to a function?
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Problem with WordPress output text (‘esc_html’ & ‘wp_richedit_pre’)
- How to apply the ‘current_page_item’ class to an archive page in `wp_list_pages()`?
- Conditional custom menu?
- What function actually renders the wp_admin_bar ? How can I call it?
- Facebook OpenGraph error, Call to undefined function wp_get_attachment_src()
- wp_enqueue_script() not working
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- Custom user role still showing up after deletion, ideas?
- Do I Need to Prefix Variables Inside Functions?
- How do I create pages within a WordPress post?
- How to change a meta value (of a published post) after X days.?
- referencing the current user in a page i created in wordpress
- Unable to use get_page_by_title() more than once per page?
- Editor cannot access Theme Options
- Add a custom function to widget code
- the_excerpt function not showing image
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Need To Resize Images Exactly Without Losing Image Details
- Problem with shortcode inside a shortcode
- How to add or delete default value theme options while activate and deactivate theme
- Echo youtube code from url or shortcode
- Removing WPML Items From the WordPress Admin Bar
- Display ACF category image on archive and single template files
- Get URLs for AJAX Filter Checkboxes WordPress
- How to get taxonomy tree ids without running expensive loops