Hook for changing excerpt content when excerpt not set

The proper hooks for modifying the post excerpt are the ones you already tried: get_the_excerpt and the_excerpt, and WordPress actually uses the former one to generate an excerpt from the full post content, if there’s no custom or manually-specified excerpt for the post — below is the relevant code in wp-includes/default-filters.php: add_filter( ‘get_the_excerpt’, ‘wp_trim_excerpt’, 10, … Read more

See if a post has a specified tag

You should wrap your condition with brackets according to PHP syntax: if (has_tag(‘Cat’, $post_id)) { $taganimal = “Cat”; } If you need to check multiple tags you can use something like foreach ([‘Cat’, ‘Dog’] as $animal) if (has_tag($animal, $post_id)) { $taganimal = $animal; break; } but it would find only the first tag listed in … Read more

How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?

You should use the PHP modulo operator for that. Since you need two different layouts, you should calculate your classes numbers according to $count % 2 and ($count + 1) % 2: <?php $count = 0; foreach ($howtoplaycontent as $hpc): ?> <div class=”row courses_row” style=”background-color: #f8f8f8″> <div class=”container”> <div class=”row” style=”padding: 15px;”> <div class=”col-lg-6 course_col … Read more

Disable posts generated from image uploads

There are a few ways to do this with updates to functions.php as well but the easiest might be to first install Yoast plugin and then use the setting for Attachment URLS that redirect it to the parent post https://yoast.com/media-attachment-urls/

Blog page error ‘Index of /blog’

There shouldn’t be a blog folder in the file manager. If there is one, your web server will load that instead of asking WordPress for the blog page. Delete the empty folder and it will work. You should never need to create folders or pages in the file manager or via FTP when using WordPress.

Reinstall WordPress while keeping attachments

Depending on how those inbound links work, this could be simpler than you think. If the links are direct to files in the file system, WordPress isn’t actually needed at all – just a corresponding path for a valid URL. So let’s say you install WP today, the ‘earliest’ folder in uploads will be 2020/09. … Read more

how can i display my posts alphabetically?

Add both orderby and order query parameters. Here is an excerpt of the PHP code you need: $query_args = array( “category_name” => “elektrotechniek”, “orderby” => “post_title”, “order” => “ASC” ); Use post_title in case you need to order your posts by title, or post_namein case you prefer to order your posts by slug. Any other … Read more

Delete post revisions only for a single post

If you need an SQL query, then this option should be suitable function src_flush_revisions () { global $wpdb; $post_id = 5//exp post id if ( isset( $timeLimit ) ) { $revision_ids = $wpdb->get_col( $wpdb->prepare( “SELECT `ID` FROM $wpdb->posts WHERE `post_type` = ‘revision’ AND `post_parent` = %d”, $post_id ) ); foreach ( $revision_ids as $revision_id ) … Read more