add_filter for specific pages

It is helpful to post your entire filter and callback code, rather than just pieces. But, I suspect that the problem is that you’re not returning $the_content outside of your conditional, e.g.: function magicalendar_get_event_page( $content ) { if ( $post->post_name == ‘magicalendarpage’ ) { // Do something to $content return $content; } } add_filter( ‘the_content’, … Read more

Adding a class to the body_class function

Actually you just need a callback for the body_class filter. Then simply check what correlation you got between your meta data and the actual value: If it is a 1:1 correlation, you can just add the result of get_field() as new body class. Example: array( get_field( ‘mem_id’ ) ) if the mem_id meta value would … Read more

Change upload directory on custom plugin page

After working on this for a bit and checking the GLOBALS variable for anything useful, it looks like the referring URL inside of the media modal is the same URL as my custom plugin page. Using that and splitting it up a bit I was able to confirm that I am on the approrpriate page. … Read more

Filter Widget Title Wrap

The filter to do this is dynamic_sidebar_params also see this tutorial on this filter at ACF’s site (even if you don’t use ACF). function prefix_filter_widget_title_tag( $params ) { $params[0][‘before_title’] = ‘<h2 class=”widget-title widgettitle”>’ ; $params[0][‘after_title’] = ‘</h2>’ ; return $params; } add_filter( ‘dynamic_sidebar_params’ , ‘prefix_filter_widget_title_tag’ );

Filtered query_vars becomes global. Why does this work?

Within the WP::parse_request() method (src) we locate the query_vars filter: $this->public_query_vars = apply_filters( ‘query_vars’, $this->public_query_vars ); and within WP::register_globals() we can see why it becomes globally accessible (src): // Extract updated query vars back into global namespace. foreach ( (array) $wp_query->query_vars as $key => $value ) { $GLOBALS[ $key ] = $value; } where the … Read more

Translating an error message

The gettext filter can be used to change strings that use the gettext functions. add_filter( ‘gettext’, ‘wpse_change_error_string’, 10, 3 ); /** * Translate text. * * @param string $translation Translated text. * @param string $text Text to translate. * @param string $domain Text domain. Unique identifier for retrieving translated strings. * * @return string */ … Read more

Add Class to Specific Paragraph of the_content()

The following bit of code adds a class to the first paragraph output by the_content: function first_paragraph($content){ return preg_replace(‘/<p([^>]+)?>/’, ‘<p$1 class=”intro”>’, $content, 1); } add_filter(‘the_content’, ‘first_paragraph’); Add the above to your theme’s functions.php file. Then in your CSS add something like: p.intro { font-weight:bold; } I can’t claim credit for this solution (see this thread … Read more

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