Set Primary category using the Yoast SEO plugin

Try instead update_post_meta($post->ID,’_yoast_wpseo_primary_category’,$childid); Use below function: function wpseoPrimaryTerm($taxonomy, $postID, $term){ if ( class_exists(‘WPSEO_Primary_Term’) ) { // Set primary term. $primaryTermObject = new WPSEO_Primary_Term($taxonomy, $postID); $primaryTermObject->set_primary_term($term); // Save primary term. $primaryTermObjectAdmin = new WPSEO_Primary_Term_Admin(); $primaryTermObjectAdmin->save_primary_terms($postID); }else{ echo ‘Class WPSEO does not exit’; } } Where $taxonomy – taxonomy name, $PostID – $post->ID, $term – $childid

Insert code when users come from an specific referer

Your post does make sense, you just want to change/add some content based on referrer, which is very common among websites. Now, as you asked just at the start of body. I don’t believe there is any standard hook in there, other than get_header();. This function is usually located at the very beginning of most … Read more

Use Filename for Alt and Title Tags

The alt tag already takes the filename but if for some reason you need to replace hyphens with spaces and include a duplicate title of the alt tag you can do something like: function wpse_120228_seomadness($html, $id, $caption, $title, $align, $url, $size, $alt) { $alttitle = str_replace(‘-‘, ‘ ‘, $alt); $img = get_image_tag($id, $alttitle, $alttitle, $align, … Read more

lazy load comments wordpress on click

Templates like the comments template need to be loaded on the page, as it relies on some global variables to know what post to load the comments for, so just pulling in the template with Javascript won’t work like that. You’ll need to create an AJAX wrapper that sets up the post data before getting … Read more

show limited tags in an article

Your code with changes: <?php $post_id = get_the_ID(); $queried_post = get_post($post_id); $user_info = get_userdata($post->post_author); // <– or: $user_info = get_the_author_meta(‘ID’) $first = $user_info->first_name; // what if it is empty or contains forbidden characters? $last = $user_info->last_name; // as obove wp_set_post_tags( $post_id, $first, true ); // <– tag slug, used in the code below // — … Read more

How to use the php if statement [closed]

You may do it this way using open/close bracket {} <?php if ( 1==2) { ?> <textarea> “Add multiple lines of text here and watch the scrollbars grow.”> </textarea> <?php } ?> In general rules you need to enclose all the if else statement using php tag and the html outside it. You may also … Read more

Config apple-app-site-association file with wordpress

OP moved this question to StackOverflow: https://stackoverflow.com/a/45399792/6471228 Answer via Alex Bauer: Since the apple-app-site-association file is not a WordPress file, you have to configure the content type at the server level. This is different depending on environment (Apache vs. nginx, for example). This can be hard, if your host doesn’t allow access to low level … Read more