Hot answers tagged

3

wp_head is an essential part of the theme, and there is too many things that might fall apart if it is not there. Hunting and fixing them one by one might be time consuming and the worthiness of the all operation questionable. In you snippet for example you want to remove things that make no sense to remove specifically only for one CPT, and if you have ...


2

First add the following code (and probably the WC Test Payment Gateway) and do a test order to get a list of all the data keys that are set in the order process via the woocommerce_after_checkout_validation filter: add_action('woocommerce_after_checkout_validation','custom_modify_order',10,1); function custom_modify_order($posted) { foreach ($posted as ...


2

Just some general remarks: Why isn't the following change working? $custom_message = get_the_title( $post->ID ) .''. $hash_tags; to: $custom_message = get_the_content( $post->ID ) .' '. $hash_tags; Note that get_the_content() doesn't take a post ID as an input parameter and it depends on global variables, like $pages that's ...


2

You shouldn't be putting arbitrary HTML into post content, instead use shortcodes! Shortcodes were intended for this situation. Otherwise you face 2 problems: Filters will escape your content via the wp_kses_post on output TinyMCE will filter/mangle/strip tags when you use the visual editor, even for the slightest of moments All of these are done for ...


2

Since plugins hook directly into wp_head nothing will happen if it's not there unless you change the plugin code. So, you'd have to create your own hook in the theme, then scan the Yoast files for any calls to wp_head and change them. Not recommended, though. A better course of action would be to generate these metatags yourself. They're pretty ...


1

This is the solution I arrived at with thanks to the pointer from @bravokeyl So, to be clear it does not add the ID's to links but by using the link slug I'm able to get the ID which is a solution for what I need. I'm using JS to pass the URL into this function and then stripping it down to the slug only which is used within get_page_by_path which then ...


1

That is due to the fact, that your filter woocommerce_breadcrumb doesn't even exist. This filter here works and pulls out all the elements, that are currently in the breadcrumb (as an array): add_filter( 'woocommerce_get_breadcrumb', 'change_breadcrumb' ); function change_breadcrumb( $crumbs ) { var_dump( $crumbs ); return $crumbs; } And this ...


1

One of the easier ways to do this is to just add the filter before your query and remove it after: add_filter( 'posts_orderby', 'filter_function' ); $something = new WP_Query( $args ); remove_filter( 'posts_orderby', 'filter_function' ); Then you can just add your function into functions.php as normal: /** * The below function filters something * ...


1

You can use output buffering to get the template output and return it in place of the emptied shortcode content: if ($pos !== false) ob_start; get_template_part('content-gallery.php'); $contentgallery = ob_get_contents(); ob_end_clean(); return substr_replace( $content, $contentgallery, $pos, strlen($shortcode[0]) );` } EDIT It might ...


1

The cookie is stored on the user's computer. The page is generated on the server. Somehow, you must make sure the cookie is transported back to the server when the user clicks on a link to fetch a second page. The instrument for this is javascript. You must send a script with the page that reads the cookie and adds the cookie content as a query_var to any ...


1

the_content is usually "executed" in the context of a loop when all relevant global data is set. You should try to mimic it by using code like function get_page_content(){ global $post; $id = $_REQUEST['id']; $post = get_page($id); setup_postdata($post); echo apply_filters('the_content', $post->post_content); //echo ...


1

To append text to the end of the titles in that widget and nothing more i.e. does not matter the URL, you can just use some CSS. <li> <a class="my-folder-categories">Category 1</a> </li> a.my-folder-categories-folder:after {content:" folder"; This will effectivly make the text appear as so: category 1 folder Be sure to add ...


1

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' ...


1

Thanks to @Max Yudin this is an answer to my problem: function user_content_replace($content) { $sentences_per_paragraph = 3; // settings $pattern = '~(?<=[.?!…])\s+~'; // some punctuation and trailing space(s) $sentences_array = preg_split($pattern, $content, -1, PREG_SPLIT_NO_EMPTY); // get sentences into array $sentences_count = ...


1

Check the documentation of add_filter() first argument is name of filter and second one is callback function name. (both are required) See the example for your case:- add_filter('bimber_facebook_sdk_src', 'change_fb_sdk_url'); function change_fb_sdk_url($current_url) { // Variable $current_url hold the current value of URL // You can manipulate ...


1

You can use the_content with an high prioriety (lower number). add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, 0); You can even use negative priority: add_filter( 'the_content', function( $content ) { return 'Hello World '.$content; }, -10); Note that this will apply everytime 'the_content' is used, no matter ...


1

There is no other global filter applied before the_content - you can use the $priority argument in your add_filter call to ensure your function runs before any others: function wpse_225625_to_the_top( $content ) { return "Hello World\n\n\$content"; } add_filter( 'the_content', 'wpse_225625_to_the_top', -1 /* Super important yo */ );



Only top voted, non community-wiki answers of a minimum length are eligible