New answers tagged

0

I'm not completely sure what you are trying to accomplish, but here's what I think. Normally you would generate a link to a comment like this: echo '<a href="' . get_permalink($comment->comment_post_ID) . '#comment-' . (strval($comment->comment_ID)) . '">'; The problem with filtering get_permalink() is that the filter must know that it is ...


0

wp_title filter is deprecated since WordPress 4.4 (see here). You can use document_title_parts instead function custom_title($title_parts) { $title_parts['title'] = "Page Title"; return $title_parts; } add_filter( 'document_title_parts', 'custom_title' ); In custom_title filter, $title_parts contains keys 'title', 'page' (the pagination, if any), ...


0

Check this out function custom_title($title_parts) { $title_parts['title'] = "Page Title"; return $title_parts; } add_filter( 'document_title_parts', 'custom_title' ); In custom_title, $title_parts contains 'title', 'page' (the pagination), 'tagline' (the slogan you specified) and 'site'. Set "title" the way you like.


0

1. You can use pre_get_comments hook: add_action('pre_get_comments', function($query) { global $pagenow; if ( is_admin() && ('your-custom-page' === $pagenow) ) { $query->query_vars['meta_query'] = [ 'relation' => 'AND', [ 'key' => 'key1', 'value' => 'meta1' ...


0

the_content will return the whole content of the post and not particular part. If you want to access your particular part, then you can go for shortcode. For eg, if you have content like this in your post Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's [mycustomtextpart] standard dummy ...


0

'meta_key=keyname' must also be present in the query so I think you'd want $args = array( 'meta_query' => array( array( 'key' => 'wpcf-stream', 'value' => $_POST['category'], 'compare' => '=' ) ), 'orderby' => 'meta_value', 'meta_key' => 'wpcf-stream', 'post_type' => 'half-day-course', 'posts_per_page' ...


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_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

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

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


0

I've found the exact solution to my question here: http://wordpress.stackexchange.com/a/17687/92505 Here's the exact code I used after some modification to make it work on my situation. Add the following code to functions.php where 'sidebar-1' is your sidebar ID. 'recent-posts' is the name of the widget your want yo hide. 12 is the length of the string ...


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


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


0

Complete code (thanks to @birgire) in case anyone else finds useful in the future: // Append Tags as Hashtags to Jetpack publicise posts if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) { function tsj_publicize_hashtags() { $post = get_post(); if ( ! empty( $post ) ) { /* Grab the tags and ...


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


0

As suggested by @Sumit, the problem was in the template: there was a test that prevented the_content() to execute when the content was empty. <?php if ( $page->post_content && have_posts() ) while ( have_posts() ) : the_post(); ?> <?php the_content(); ?> <?php endwhile ?>


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


0

Note that to remove a filter callback from the woocommerce_email_content filter, you first need to have it registered via: add_filter( 'woocommerce_email_content', ...some-custom-callback... ); but it looks like you're trying to remove the inline styles from the message. I guess you need the text/html content type, so try instead to override the styles ...


0

<?php $string = 'Sentence 1. Sentence 2? Sentence 3! Sentence 4... Sentence 5… Sentence 6! Sentence 7. Sentence 8. Sentence 9… Sentence 10... Sentence 11. '; $sentences_per_paragraph = 3; // settings $pattern = '~(?<=[.?!…])\s+~'; // some punctuation and trailing space(s) $sentences_array = preg_split($pattern, $string, -1, PREG_SPLIT_NO_EMPTY); // ...


0

@Dan meant this: <nav role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement"><?php wp_nav_menu([ 'container' => '', 'items_wrap' => '<ul>%3$s</ul>', ... ]); ?></nav>


0

Since your new theme doesn't register the shortcodes they're regarded as plain text. Any attempt at filtering is useless, because as far as WordPress is concerned they aren't shortcodes. The easiest way to solve this is to register the shortcodes in your new theme and hook them to an action that does nothing besides removing the shortcode.


0

try this add_filter( 'get_the_excerpt', 'strip_shortcodes', 20 ); or try this edit echo strip_shortcodes( get_the_excerpt() ); if shortcode is not register with wordpress function add_shortcode add_filter( 'the_excerpt', 'remove_shortcodes_in_excerpt', 20 ); function remove_shortcodes_in_excerpt( $content){ $content = strip_shortcodes($content); ...


-1

Try: $excerpt = $post->post_excerpt; $excerpt = apply_filters('the_content', $excerpt); echo $excerpt; Or: $excerpt = $post->post_excerpt; $excerpt = apply_filters('the_excerpt', $excerpt); echo $excerpt;


0

function wpsesess_ddecode_excerpt( $excerpt ) { return strip_shortcodes( $excerpt ); } add_filter( 'the_excerpt', 'wpsesess_ddecode_excerpt' ); EDIT Can you please post this in functions.php and let me know?


0

It is normal for content to be accessed multiple times. For example SEO plugins need to do this to access it and generate meta data from. Also it is a filter hook. Filters should never echo anything to the page, they are meant to modify passed value and return it. If you do want to do something at that point, but only within the loop then in_the_loop() is ...


0

You might want to load all the items on the page at the same time, and use jQuery to display however many at a time. So for example: By default you could load (to the DOM) and hide all of them, then load 4 at a time using jQuery's slice Here's an example for my videos, however you could also hide the previous 4 videos before loading the next 4 to simulate ...


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 */ );


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


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


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


0

I solve the problem by hooking my function to delete_attachment hook, then putting the debug trace inside my function and filtering the wp_delete_attachment, by this I can retrieve what file and line number where the wp_delete_attachment is called. add_action( 'delete_attachment', 'your_function' ); function your_function($postid) { $trace = ...


0

add_filter ( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 ) Hook a function or method to a specific filter action. WordPress offers filter hooks to allow plugins to modify various types of internal data at runtime. A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each ...


0

You need to hook your function to delete_attachement hook, but you also need to remove some extra functions that are called before calling your hooked action to reach the right caller of wp_delete_attachment(). Here's a possible implementation... function my_backtrace( $post_id ) { $bt = debug_backtrace(); array_shift( $bt ); // Remove ...



Top 50 recent answers are included