Hallo Daniel,
danke für Deine Antwort.
ja, es muss natürlich is_single() heißen. Gibt es denn eine Möglichkeit wp_enqueue_script() nur für bestimmt post types (in meinem Fall Blogposts) zu verwenden.
Ja, das würdest du dann auch einfach mit is_single machen.
Könnte es ja dann auch mit der if-Anweisung machen, würde dann so aussehen:
[COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]if ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]is_single[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#007700][FONT=monospace])): [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
[/FONT][/COLOR][COLOR=#303336]add_action[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]'wp_enqueue_scripts'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]'test'[/COLOR][COLOR=#303336]);[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]function[/COLOR][COLOR=#303336] test[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]{[/COLOR][COLOR=#303336]
wp_enqueue_script[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]'external-script'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]'//a.teads.tv/page/58207/tag" async="true"'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] array[/COLOR][COLOR=#303336](),[/COLOR][COLOR=#7D2727]'3'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#101094]true[/COLOR][COLOR=#303336]);[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#303336]}
<?php [COLOR=#007700][FONT=monospace]endif; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
[/FONT][/COLOR][/COLOR]bin mir aber mit der Script-Anweisung [COLOR=#303336]wp_enqueue_script[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]'external-script'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]'//a.teads.tv/page/58207/tag" async="true"'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] array[/COLOR][COLOR=#303336](),[/COLOR][COLOR=#7D2727]'3'[/COLOR][COLOR=#303336],[/COLOR][COLOR=#101094]true[/COLOR][COLOR=#303336]); nicht sicher, ob die richtig ist??
Viele Grüße[/COLOR]
Alles anzeigen
Nein, das wird so nicht funktionieren. Du beendest ja den PHP Script Block, obwohl dazwischen dann auch PHP steht. DIe Reihenfolge ist auch unglücklich. Ich würde die if-Anweisung eher innerhalb von der Funktion setzen.
Probier mal folgenden Code (der muss in die functions.php):
function register_my_scripts() {
if ( [COLOR=#0000BB][FONT=monospace]is_single[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#007700][FONT=monospace])[/FONT][/COLOR] ) {
wp_enqueue_script( 'teads_tv_js', '[COLOR=#000000]//a.teads.tv/page/58207/tag[/COLOR]', '', '', true );
}
}
add_action( 'wp_enqueue_scripts', 'register_my_scripts' );
Ich habe es jetzt nicht getestet, aber das sollte dein Script automatisch im Footer laden.
In dem Fall wäre aber das async weg. Wenn du das erhalten möchtest, musst du noch folgenden Filter ergänzen (auch ungetestet, gehört auch in die functions.php):
function add_async_attribute($tag, $handle) {
if ( 'teads_tv_js' !== $handle )
return $tag;
return str_replace( ' src', ' async="async" src', $tag );
}add_filter('script_loader_tag', 'add_async_attribute', 10, 2);
Edit: ich hatte aus versehen wp_enqueue_style statt wp_enqueue_script. Ist jetzt korrigiert.