Insert term when page is published – avoid duplicates after edits

I suggest post status transitions that runs only when your set conditions are met. Example: add_action( ‘transition_post_status’, ‘add_awesome_terms’, 10, 3 ); function add_awesome_terms( $new_status, $old_status, $post ) { // only run when it’s a page, new status is publish and old status isn’t publish if ( $post->post_type == ‘page’ && $new_status == ‘publish’ && $old_status … Read more

How to allow users to view pending posts of a specific custom post type?

You need to make a custom query to display these pending posts. Here is an example using get_posts(): $args = array( ‘post_type’ => ‘post_type_name’, ‘post_status’ => ‘pending’, // -1 shows all ‘posts_per_page’ => -1, ); $pending_posts = get_posts( $args ); foreach( $pending_posts as $pending_post ) { // post object properties $id = $pending_post->ID; $title = … Read more

Add Defer Attributes to WordPress Scripts with consistent versioning

Use the $wp_scripts, which is a global variable to get the version of a registered script. add_filter( ‘script_loader_tag’, ‘script_handler’, 10, 3 ); function script_handler( $tag, $handle, $src ) { // the following global contains all the information you need global $wp_scripts; $ver = $wp_scripts->registered[ $handle ]->ver; // do your thing } Note, this is exemplary.

Is it possible to use multiple spaces in title?

As you can see in the Codex, the filter actually has 2 arguments, which needs to be stated: add_filter( ‘the_title’, function ( $title, $id = null ) { return preg_replace(‘#(\s{3})#’, ‘…’, $title); }, 10, 2 ); You could as well just use a placeholder that you replace on the fly – might be easier. In case … Read more

Manipulating show_on_front, page_on_front, page_for_posts and template hierarchy

Ok, got it working. I was returning a property of a serialized option within the callbacks for the filters: add_filter(‘pre_option_page_on_front’, ‘page_on_front’); function page_on_front() { $options = get_option(‘theme_options’); return $options[‘page_on_front’]; } add_filter(‘pre_option_page_for_posts’, ‘page_for_posts’); function page_for_posts() { $options = get_option(‘theme_options’); return $options[‘page_for_posts’]; } The returend values were numbers, but strings. Typecasting them to int got it working.

the_excerpt filter with an empty excerpt

If you are talking about excerpt set manually in the excerpt field of post then you can use following code in the functions.php file of your child theme or plugin to display default excerpt if no excerpt it set. function display_default_excerpt( $excerpt ) { if ( has_excerpt() ) { return $excerpt; } else { return … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)