New answers tagged

0

I'm not sure if I understand well your question but, you can get a post data inside another post this way: $post = get_post( 123 ); // Where 123 is the ID $output = apply_filters( 'the_content', $post->post_content ); You can also use wp_query if you want more control.


0

Using a cookie it would be: function get_contact_team_page_content ( $content ) { if (isset($_COOKIE['alternative_content'])) { $contact_team = get_post( (int)$_COOKIE['alternative_content'] ); // e.g. contact-team page ID unset($_COOKIE['alternative_content']); return $contact_team->post_content; } return $content; } add_filter( '...


0

You can try the_content filter something like below to load a content from a different post/page function get_contact_team_page_content ( $content ) { // Condition based on user selection via popup e.g. $_GET or $_POST if ('condition') { $contact_team = get_post(14); // e.g. contact-team page ID $content = $contact_team->...


0

I was using a comma instead of a colon


0

The reason for this is simple: It's not ment to be called twice! The get_header() function loads all necessary scripts and styles for the page to be fully working. That also means all plugin files, and all Hooks or Filters that are ment to be loaded for the header. Though I have never tried this, I guess that WordPress is skipping all scripts, when it is ...


0

The actual templates are loaded with require_once, so PHP automatically ignores the second attempt to load them. (You will trigger the 'get_header' hook twice though.) Here's the relevant code in get_header(): $templates[] = 'header.php'; if ( ! locate_template( $templates, true, true, $args ) ) { return false; } The third parameter to ...


1

You can also hook the items of the menu: wp-includes/nav-menu-template.php /** * Filters the HTML list content for navigation menus. * * @since 3.0.0 * * @see wp_nav_menu() * * @param string $items The HTML list content for the menu items. * @param stdClass $args An object containing wp_nav_menu() arguments. */ $items = apply_filters( '...


0

just change the $post->ID with get_post_thumbnail_id(), and possibly we can delete also the global $post; if( ! ( function_exists( 'add_alt_image_content' ) ) ) { function add_alt_image_content( $content ) { if ( is_single() && in_the_loop() && is_main_query() ) { global $post; $image = get_post(...


2

I also found that Cloudflare Rocket Loader would cause javascript errors in this situation. When the .js file was marked to be ignored, but the inline js was unable to be so marked, undefined errors would occur when the script tried to access the async-loaded inline data. The approach detailed in How to intercept already localized scripts only allows you to ...


0

The render_block filter works for this - I just tested on a fresh install. However, you'll have to use the final HTML, so it gets a bit ugly. The following code will copy the first <a> tag and wrap the copy around each <time> tag in the list. \add_filter('render_block', function($content, $parsed): string { // skip other blocks if ...


1

The main difference between an action and a filter can be summed up like this: an action takes the info it receives, does something with it, and returns nothing. In other words: it acts on something and then exits, returning nothing back to the calling hook. a filter takes the info it receives, modifies it somehow, and returns it. In other words: it filters ...


0

Am I using this hook incorrectly No, you're not. is there another way to get the ID? Yes, try this: function add_menu_field( $item_id, $item, $depth, $args, $id ) { $id2 = 0; if ( ! $id && isset( $_GET['menu'] ) && $_GET['menu'] ) { $id2 = absint( $_GET['menu'] ); } elseif ( ! $id && ! isset( $_GET['menu'] )...


1

Your answer above was close but is should be add_action( 'upgrader_process_complete', 'wp_answ_355114' ); not do_action( 'upgrader_process_complete', 'wp_answ_355114' ); noting that this is only the case when a plugin is updated view WP plugin updates.


Top 50 recent answers are included