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
- remove empty paragraphs from the_content?
- Set JPEG compression for specific custom image sizes
- Define custom Page Template without its own .php file
- syntax for remove_filter in parent theme with class
- Convert hyphen to underscore in permalinks
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- Override parent theme function that is not hooked or in the functions.php file
- Programmatically Add Font-Awesome Icons to Category Widget
- Remove bulk actions based on user role or capabilities
- How to Acheive the custom woocommerce category template
- Removing title from page
- Hide some items from Screen options in dashboard for products
- Assign category using custom field?
- Adding body class when post contains a specific shortcode
- Replace Archive Widget Link Text
- How To Get WordPress Categories Link List?
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Best way to programatically add “rel” attributes to page and post images
- Limit filter upgrader_post_install to a single plugin
- Changing post category from dropdown
- How to update feed only 2-3 times a week (for Feedburner email)?
- Remove function or filter
- Get the category name outside of the loop in category.php
- Is it possible to change any of the HTML/URL returned from the_category()
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Adding HTML to the end of every post with the Block Editor
- Unset Category if other Category is unset during post transition
- Show Primary Category first when I display post categories
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- Run wp_kses_decode_entities on atom feed?
- Filtering out the #more anchor link that gets produced by
- Can’t filter wp_get_attachment_link
- append to existing parent theme function
- Get category URL for current post
- Override the WordPress core function wp_referer_field
- How can I add a filter for specific categories on functions.php?
- How to add custom JavaScript in functions?
- Remove a category from a post when saving a new post
- 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
- How to add_filter html template to middle of content
- Redefine function arguments before rendering
- How can I add a class to a nav li depending on URL?
- Access category within rss2_head hook?
- Combine embed_oembed_html and oembed_result
- login_headertitle is deprecated since version 5.2.0
- Filter to wp_list_authors
- Image loading function not working on archive.php template
- Problem with calling custom function in a foreach loop
- The_content and Preg_replace in loaded Iframe [closed]
- “All posts” in the category widget
- 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]
- 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
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- Get slug of current category in functions.php
- how can I add filter in specfic field in my website?
- Display a list of random terms from custom taxonomy with shortcode
- Change category display name function
- Customizing the wp_video_shortcode output with add_filter
- Overwrite text in a complicated filter hook
- How to add HTML into error message
- Removing comment lines from all enqueued js files using a filter function
- remove_filter function to unhook twentysixteen parent theme function
- only update titles of single posts
- OOP Switch statement with array as parameter
- Custom Function.PHP Code Not Working on One Site
- How can I automatically delete comments that contain a URL?
- Appending „read more” to the excerpt conditionally
- function replace_text for entire page
- add product thumbnail to checkout page only and include variation name
- ACF Filter return value
- Which method is more correct for removing WooCommerce Extensions menu item?
- Hide disclaimer from summary excerpts
- different body classes for each category
- Only seems to be displaying one child when there are supposed to be multiple
- Why might wptexturize have become re-enabled?
- Shortcode to eliminate and replace with
- functions.php filters not applied in AJAX call
- Problem in outputting shortcode
- Settings in functions.php used by a plugin
- Allow tags and attributes in post and pages content
- Override parent theme function that is not hooked or in the functions.php file
- How to get tags and categories?
- Can’t change excerpt length and more tag
- Filter to strip unnecessary attributes
- Warning: call_user_func_array() expects parameter 1 to be a valid callback
- How can I modify or filter this variable in an existing class? (Mai Theme)
- Get category of post inside save_post hook