Try the following code:
function new_title( $title ) {
if(in_the_loop() && !is_singular('page')) {
$picArray = array(
'3' => '⚠',
'5' => '⛅',
);
$cats = get_the_category();
$cat = $cats[0]->term_id;
$title = $picArray[$cat] . ' ' . $title;
}
return $title;
}
add_filter( 'the_title', 'new_title' );
First, we check if we are in the loop, and our post is not a page. Variable $picArray
is an associative array of {category id} => {emoji’s html identity} pairs. Of course, you have to build this array to match your values.
Related Posts:
- Add body class of category parent
- Manipulate Output of wp_list_something: select menu instead of li’s
- Setting a default text for excerpts of a particular category
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Need help “sanitizing” a custom function that pulls category slug into body class
- allow only one post in specific category
- Add Element as a Filter to the_content
- Override the WordPress core function wp_referer_field
- Modify post filter to set custom number of posts per page and exclude child posts
- Make wp_link_pages() suitable for Twitter Bootstrap markup
- How can I add a filter for specific categories on functions.php?
- How to obtain the recent posts without their content in an efficient way?
- How to add custom JavaScript in functions?
- Running script based on Category
- Remove a category from a post when saving a new post
- How to fix get_the_category function returning incorrect slug?
- How to edit the Tags within the image file URLs?
- How would I go about replacing this function in my child theme located in inc/template-tags.php
- Retrieve a value from Yoast SEO to use to set a default twitter card image honoring overrides
- Return category name with & Ampersand doesnt work
- Can’t properly set the_title add_filter to show short_URL
- Add_filter when value is no variable?
- How to add_filter html template to middle of content
- (Woocommerce) Order by price when entering specific category
- Filter an WordPress Function in (general-template.php)
- Redefine function arguments before rendering
- How to edit classes in body tag?
- Filter nav menu items HTML tags and wrap inner text with span
- Possible to hook into Media Library preview File column and use a custom image?
- How can I add a class to a nav li depending on URL?
- Access category within rss2_head hook?
- issue with if/elseif in_array inside foreach loop display only one post
- Randomizing wp_tag_cloud() in child theme
- Modify gform_other_choice_value for specific form and specific field in Gravity Forms
- Combine embed_oembed_html and oembed_result
- login_headertitle is deprecated since version 5.2.0
- Set “woocommerce_is_purchasable” to false for specific “$product->is_stock_status”
- add_filter to specific WooCommerce Category
- How to rewrite wordpress search to work on specific category
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Filter to wp_list_authors
- How to add custom li item to wordpress menu
- Image loading function not working on archive.php template
- Native gallery custom html output
- Exclude Category ID in function
- Problem with calling custom function in a foreach loop
- The_content and Preg_replace in loaded Iframe [closed]
- Specify multiple categories for custom post template – FATAL ERROR
- How to edit/replace Parent functions.php function in Child Theme to add “Walker” class
- “All posts” in the category widget
- Functions Filter Question [closed]
- Is it possible to use add_filter in an included file in the child theme’s functions.php?
- Insert Content Before div#main from the functions.php File
- Add Adsense code between job listings – wp job manager plugin
- Get Attachment Category Name
- Problem with images URL after filter applying
- remove_action not working, even after changing priority [duplicate]
- remove/hide wp-editor
- Replace header image on all other pages but home – URL issue
- Add a class to post if it has been recently updated
- search form leads to 404
- how to add_filter to non hook function
- Change Default Content when Creating a Post based on Previous Category Choice
- Changing the text of Upload/Insert on Posts and Pages Screen
- Any adverse effects of adding apply_filters to a function?
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- Conditional custom menu?
- Display ACF category image on archive and single template files
- Get URLs for AJAX Filter Checkboxes WordPress
- Get slug of current category in functions.php
- how can I add filter in specfic field in my website?
- How to display an image before title text in menu items
- Display a list of random terms from custom taxonomy with shortcode
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Change category display name function
- Customizing the wp_video_shortcode output with add_filter
- Filter works on last selection but no others
- Overwrite text in a complicated filter hook
- Display link to category over featured image
- How to add HTML into error message
- Save_post – Warning: Cannot modify header information
- custom error message for empty username and password using authenticate filter not working
- Removing comment lines from all enqueued js files using a filter function
- Add #primary at the end of navlink permalinks on single posts
- post value to function with Ajax and jQuery
- How Do I Unhook This Parent Theme Function?
- remove_filter function to unhook twentysixteen parent theme function
- Remove the ‘category’ url for one category type
- Allow user only create specific tags
- only update titles of single posts
- OOP Switch statement with array as parameter
- Custom Function.PHP Code Not Working on One Site
- Adding new Category does not refresh the backoffice
- How do i tweak my wp Post title base on category of the post
- Child theme remove parent filter in functions
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- How to add class dynamically from templates
- Prevent function from triggering on current page
- Assign IDs to headings in ACF using functions.php