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
- How do I get the current edit page ID in the admin?
- Removing Metabox for “Slug” without removing functionality
- Does hooking into the same action multiple times drain memory?
- Apply custom role capabilities to administrator (without plugin)
- is_front_page not working in functions.php
- VERY new to coding – keep breaking site trying to add to functions.php
- How to enqueue JavaScript for specific WordPress pages only?
- Passing HTML in WordPress Shortcode arguments
- Exclude Empty Child Categories in Menu
- Convert User ID’s to User Names in a single.php file
- Custom roles can’t access to wp-admin
- How to specify which Gutenberg blocks are available in the editor for a page template
- Custom Shortcode, functions PHP WP_Query loop
- wpautop – disable tags, keep tags
- How do I pass arguments for multiple functions hooked to a single action?
- Can’t load WP function into external function
- Theme functions.php file auto delete everyday [closed]
- Two Types of settings in WP – The Doubt
- Generating dynamic css into custom file [closed]
- Events: Check for other event with same start date and category [closed]
- Function coding error concatenating quotes I think
- Need print logo without any ID & class
- Can we create our own theme’s function.php?
- Not all CSS elements transferring via parent to child?
- Reset postdata not working on WP_Query in functions.php
- Filter nav menu items HTML tags and wrap inner text with span
- Using Static HTML instead of the `home_url()` WP function
- How to append classname to body tag if guest user
- add_filter to specific WooCommerce Category
- Can I include a custom PHP function in a WordPress function?
- How do I preserve changes to a theme’s functions.php across updates?
- Unable to Change “Pages:” Before WP_LINK_PAGES
- how can I change all wordpress media file url to custom cdn url?
- Save_post – Warning: Cannot modify header information
- Modify content inside post before first publish
- Pass an argument into a function to extract from array
- how to remove a tag in the_category function
- Copying a widget class to functions.php results on a blank page
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Changing the register url is not working
- Newest comments first not working
- Pass arguments to function class with do_action()
- How to a override parent theme page that has been included with require_once?
- Can I use a function to return HTML and the result of another function?
- Excerpt length: get 2 paragraphs
- Remove heading tags on line break
- I want to add the alt attribute to all the photos!
- Creating mixture of shortcodes to use in the visual/text editor
- Add functionality to block comment authors in the Comment edit pag