The problem with your first approach is that you check conditional tags too early. is_tag
will work only after the $wp_query
is computed, so there is no point in checking it directly in functions.php
file.
And there is one more problem with both approaches – you use wrong conditional tag…
is_tag
checks if a Tag archive page is being displayed… So it’s not what you’re looking for.
And here’s a solution:
function add_something_to_post_title( $title ) {
if ( has_tag( 162 ) ) {
$title="something " . $title;
}
return $title;
}
add_filter( 'the_title', 'add_something_to_post_title' );
Related Posts:
- Issues with title-tag and document_title_parts
- How to edit the Tags within the image file URLs?
- Allow user only create specific tags
- 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
- 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 override filter in child theme?
- Removing title from page
- Hide some items from Screen options in dashboard for products
- get_the_excerpt() not returning anything when post has no excerpt
- How to change a certain text or term of WordPress into a custom into the whole site?
- Adding body class when post contains a specific shortcode
- Replace Archive Widget Link Text
- 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
- Adding a class to tag list in a function
- How to update feed only 2-3 times a week (for Feedburner email)?
- Manipulate Output of wp_list_something: select menu instead of li’s
- Remove function or filter
- Short_title character problem
- 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
- Retrieve tags data in post body
- Remove H1 / title / Underscore – without CSS
- Echo tags used to describe the theme
- How to append to title via functions.php for auto-posting plugin [duplicate]
- Passing values from a widget to a function within a plugin
- Adding an external HTML link to a post thumbnail
- Replace a menu with widget or a custom template file programmatically
- woocommerce change currency per category [closed]
- 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
- Override the WordPress core function wp_referer_field
- Modify post filter to set custom number of posts per page and exclude child posts
- How to add custom JavaScript in functions?
- Setting a default text for excerpts of a particular category
- Add_filter when value is no variable?
- How to add_filter html template to middle of content
- Function extending with if query in functions.php
- Redefine function arguments before rendering
- Best way to handle lack of titles in microblogging
- Possible to hook into Media Library preview File column and use a custom image?
- Combine embed_oembed_html and oembed_result
- login_headertitle is deprecated since version 5.2.0
- How to display the_archive_title() and the_archive_description() – “weird” interaction
- Filter to wp_list_authors
- Native gallery custom html output
- The_content and Preg_replace in loaded Iframe [closed]
- Add Adsense code between job listings – wp job manager plugin
- Sort and display pages with specific custom field (not tag)
- Replace header image on all other pages but home – URL issue
- Function to echo (or display?) wordpress tags in the head section
- Echo post title in post
- Any adverse effects of adding apply_filters to a function?
- how can I add filter in specfic field in my website?
- Adding custom social icons to the social media icon block in the Gutenberg editor?
- Customizing the wp_video_shortcode output with add_filter
- How to add HTML into error message
- Removing comment lines from all enqueued js files using a filter function
- Remove text after a dot and a colon in Woocommerce product title
- post value to function with Ajax and jQuery
- How Do I Unhook This Parent Theme Function?
- Child theme remove parent filter in functions
- function replace_text for entire page
- Removing sanitize_title_with_dashes Function with The Real Title
- add product thumbnail to checkout page only and include variation name
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- Graphic before title – Specific Category
- Which method is more correct for removing WooCommerce Extensions menu item?
- Hide disclaimer from summary excerpts
- Display page number on custom page title function
- 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
- Search and Replace Script Loader in Head Only Works in Footer
- Automatically add tag if a checkbox is checked
- functions.php filters not applied in AJAX call
- Problem in outputting shortcode
- Changing the color of post title [closed]
- Settings in functions.php used by a plugin
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- 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
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- If two tags in the middle i need comma
- Filter to strip unnecessary attributes
- Rename file after title , one small problem
- Bulk set Post Title as Tag where Tag is Empty Function
- 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)