Wrapping shortcode content in a span or link

Get out of the switch block before placing the final return statement. if you place return at the end of the switch block that way, the switch block already ends before it gets to the return statement (because of the previous matching break statements). The correct CODE will be: // just in case $summary is … Read more

Get child-pages slugs of current page into js-file

I just found what is arguably a cleaner way to do this…thanks to this other WPSE question How do I add a php statement to a jQuery string. I never new about wp_localize_script() until reading the answer to that question (I love WPSE :-). PHP add_action (‘wp_enqueue_scripts’, ‘localize_js’) ; function localize_js () { global $post … Read more

WordPress Add advertising ads befor and after content with periority [closed]

You’ll want to use add_filter() for each advertisement so you can set the priority accordingly. Example: // Ad 1 function myprefix_ad_1( $content ) { $ad = ‘Your ad code’; return $ad_1 . $content; // this one is before } add_filter( ‘the_content’, ‘myprefix_ad_1’, 10 ); // Ad 2 function myprefix_ad_2( $content ) { $ad = ‘Your … Read more

str_replace not preserving whitespace

Did you clear cache after making changes with trim()? Try with: str_replace( trim( $parent->name ), $link, $intro_text ); Are you sure that the term is Upbeat Electronic music and not UpbeatElectronic music? Try with this to be sure: str_replace( trim( $parent->name ), ‘ ‘ . $link, $intro_text );

How to mark posts as visited

You can add a special custom field when a logged user visits any page. A way to do this without editing the template file, is to use the filter the_content add_filter(‘the_content’, ‘wpse_259159’); function wpse_259159($content){ // check the user ID $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) { // Not logged in. } else … Read more

Does WordPress function replace_hello() exists?

This is custom function the author uses to show how to use the_content filter. If you look at the line after the function add_filter(‘the_content’, ‘replace_hello’); this is saying to call the custom function replace_hello when encountering the the_content filter