Replase post title based on conditions

So I would like to replace the entire title of posts in WordPress bases on user behaviuor and role. Please note that I would like to replace the entire post title and not the prepend or append text to it. Each post has a 'default' title, which is the title of the post, like "Make No.1245/12.02.2022 on model 2376/2021". The alternative title would be "Make No.*******/********.2022 on model *******/2021" basically replacing certain parts of the title with asterisks, essentially hiding …
Category: Web

Blog Title not showing up on main Blog page

I cannot get the main blog page with the current blog to show the current blog title. It shows on all other pages, just not the current/most recent blog. Any help will be greatly appreciated. Thank you. <div id="page"> <div id="contentleft"> <?php if ( $paged < 2 ) { // Do stuff specific to first page?> <?php $my_query = new WP_Query('category_name=featured&showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?> <div class="featurepost" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link …
Category: Web

How to get all post titles starting with numbers and symbols?

I want to get all posts which are starting with a number (0-9) or symbols, in a list. I managed to get it work for letters, but this one is harder for me. Can someone help me out please? I tried adding this in my existing code, but it didn't work: $this_char = strtoupper(mb_substr($post->post_title, 0, 1, 'UTF-8')); if (strpos('0123456789',$this_char) !== false) $this_char = '0-9'; if ($this_char != $last_char) { This is my code: <?php $first_char = 'A'; $postids=$wpdb->get_col($wpdb->prepare(" SELECT ID …
Category: Web

How to search posts by title with special characters in WP_Query?

I have built a custom query for a website where I have a custom post type named "Program" (i.e). On this custom post type, let's say I have the taxonomy "Level" where I have some choices. The way I have built the code, you can create as many page with the same title but with different taxonomies. On the frontend, I use a custom WP_Query to fetch all posts with the same title and display a menu to link them …
Category: Web

change title separator

tell me how permanent the links to change the splitter from vertical to horizontal of the main page write website. | — http://joxi.ru/a2XlxQXcyeKPj2 The name of the site | short name The name of the site — short name
Category: Web

Remove "Private" + ":" in title does not work

I would like to remove the "private" prefix for each post title. I found the filter here. I managed to removed the word "Private" but when I concatenate with " : ". That does not work anymore. I checked $title value before the str_replace and it´s already translated with " : ". Class FrontEnd{ protected function front_end_init() { add_filter( 'the_title', array( $this, 'remove_private_prefix' ) ); } public static function remove_private_prefix( $title ) { $title = str_replace( __( 'Private' ) . …
Category: Web

get_posts() loop returns the same the_title() for each post

I'm using get_posts() to fetch posts from a particular category to display at the top of my homepage, separate from the main homepage Loop. Everything seems to work fine, but for the title (returned through the_title()) which is always the same; the title of the first post fetched by get_posts(). the_permalink() does the same as well, but the_excerpt() returns the correct result for each post. Here's my code (I have removed only a few lines for fear I might inadvertently …
Category: Web

How to ignore WP_ERROR caused by "get_the_excerpt" method in an AJAX call?

function get_post_data(){ $post_id = $_POST['post_id']; ... $data['title'] = get_the_title( $post_id ); ... $data['excerpt'] = get_the_excerpt( $post_id ); ... echo json_encode( $data ); wp_die(); } The above code shows the scheme of the ajax call. Some data should be retriven from a post given by its ID outside the LOOP. This seems to work when the content fields like title and excerpt not empty. But when empty I get an Internal Server Error (500: admin-ajax.php not found). When I debug the …
Category: Web

Filter the title to only affect the_title() template function

I am using the_title filter to add an HTML snippet under the title, as follows: I only want the output to happen for the main title in the posts or page view. That's why I added an early return to make sure that the filter only applies if is_singular() returns true: if ( ! is_singular() ) { return; } But there is an issue, since the title may be loaded in other places inside the single view template. For example, …
Category: Web

Shortcode Not Working in Slider When Added To Post Title

I've coded a shortcode to add manually to specific post title fields so i can style part of a title add_shortcode( 'green', 'green_shortcode' ); function green_shortcode( $atts, $content = 0 ) { $a = shortcode_atts( array( 'class' => 'green', ), $atts ); return '<span class="' . $a['class'] . '">' . $content . '</span>'; } This works on the single post titles but doesn't parse the shortcode when pulling the title into a slider. This is the messed up HTML output …
Category: Web

Don't see add_filter result in the site front page

I modified the site title the 'the_title' filter. I am using ACF pro repeater, I want to achieve is that if there is content in the repeater a + will be added to the post title. I wrote this script: function mm_title_update( $title, $id = null ) { if ( ! is_admin() && ! is_null( $id ) ) { $post = get_post( $id ); if ( $post->post_type == 'info' ) { $is_index = have_rows('index_copy', $post); //acf repeater field //check if …
Category: Web

Trim Titles Only On Some Pages

I Need to Trim the h2.entry-title, including whitespace and special character Only On Homepage, Category Pages, and Tag Pages. (eg. Gowland Remote Control Car – RC Cars Xmas Gifts) I Need All Titles Like This (Gowland Remote Control Car) I need to trim all the characters after “-” Please Help me with this. Thanks
Category: Web

Changing Title Tag on Shop Archive Page (current solution reverting to Title of First Product in Loop)

Firstly, add_theme_support( 'title-tag' ); is enabled in my theme. I have two filters to modify titles, this one hooking on to the_title add_filter( 'the_title', 'custom_account_endpoint_titles', 10, 2 ); function custom_account_endpoint_titles( $title ) { // Currently only have conditions here for My Account pages (is_account_page()) // example: if ( isset( $wp_query->query_vars['edit-account'] ) && is_account_page() ) { return $title; } Secondly I have another function which fixed some title issues on Account pages as well (if I do not add this, the …
Category: Web

Multilanguage website get the title, on different languages

I am working on a website, and I am using Polylang to translate it to a different language. In my code I want to get a page title, and display it. My issue is I cannot get it by ID or page_by_path because its going to display the English version of the page on every language. For example: I want to display the Contact page title on english Contact and on another language its equivalent translated contact page title. Is …
Category: Web

Modify WordPress Page Title (<head></head>)

I'm trying to modify the WordPress page title. However I'm fairly new to WordPress functions, hooks (filters &amp; actions) and so on. What I could achieve is to change and modify WordPress titles in the &lt;body&gt;. I also was able to change to Page title (&lt;head&gt;), but not to modify it. E.g.: Original page title: My house is red Modified page title (| -&gt; is used for seperate examples): My house is green | My house is red and blue …
Category: Web

How do I hide the current page's title?

I have this code: add_filter( 'the_title', function() { return ""; }); Or, respecting the hook's arguments: function remove_title( $title, $id ) { $title = ''; return $title; } add_filter( 'the_title', 'remove_title', 999, 2); Which is being placed in a custom made page, my template (used by that page) being: get_header(); ?&gt; &lt;div id="primary" class="content-area"&gt; &lt;main id="main" class="site-main"&gt; &lt;header class="entry-header"&gt; &lt;?php the_title('&lt;h1 class="entry-title"&gt;', '&lt;/h1&gt;'); ?&gt; &lt;/header&gt;&lt;!-- .entry-header --&gt; &lt;?php while ( have_posts() ) : the_post(); ?&gt; &lt;article id="post-&lt;?php the_ID(); ?&gt;" &lt;?php …
Category: Web

How to output the title of the blogs home page

I am using a static frontpage and a page for my blogposts. In my header.php I want to display the title of the selected page of my blogposts. For example: &lt;?php if( is_home() ) echo '&lt;h1&gt;' . get_the_title() . '&lt;/h1&gt;'; ?&gt;&lt;nav&gt; ... &lt;/nav&gt; But of course get_the_title() returns the first element of the displayed posts and not of the page itself. How can I display the title of the assigned home page?
Category: Web

Post title not displaying as recorded in the wp_posts table

I have a WordPress install in which the "post_title" field from the "wp_posts" table is not making it into the WP_Post->post_title variable. So, for a given post in the wp_posts table that has a correct post_title value of say (retrieved via a direct MySQL query): "My First Post" Retrieving the post title via any basic WordPress method, such as: &lt;?php print the_title(); ?&gt; ... or ... &lt;?php $this_post = get_post(); print $this_post-&gt;post_title; ?&gt; Instead of the post's title I get …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.