Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
103 lines (76 loc) · 2.77 KB
/
Copy pathfunctions.php
File metadata and controls
103 lines (76 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
// Register Nav Walker class_alias
require_once('wp_bootstrap_navwalker.php');
// Theme Support
function wpb_theme_setup() {
add_theme_support('post-thumbnails');
// Nav Menu
register_nav_menus(array(
'primary' => __('Primary Menu')
));
function my_theme_scripts() {
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom_script.js', array( 'jquery' ), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_theme_scripts' );
// Post Formats
add_theme_support('post-formats', array('aside', gallery));
}
add_action('after_setup_theme', 'wpb_theme_setup');
// Excerpt Length Control
function set_excerpt_length() {
return 20;
}
add_filter('excerpt_length', 'set_excerpt_length');
function new_excerpt_more( $more ) {
return '';
}
add_filter('excerpt_more', 'new_excerpt_more');
function add_login_logout_register_menu( $items, $args ) {
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( is_user_logged_in() ) {
$items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Log Out' ) . '</a></li>';
} else {
$items .= '<li><a href="' . wp_login_url() . '">' . __( 'Sign In' ) . '</a></li>';
$items .= '<li><a href="' . wp_registration_url() . '">' . __( 'Register' ) . '</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
function wpdocs_scripts_method() {
wp_enqueue_script( 'progress-bar', get_stylesheet_directory_uri() . '/js/progress_bar.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_scripts_method' );
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:block; text-align:center;"
data-ad-layout="in-article"
data-ad-format="fluid"
data-ad-client="ca-pub-1799202409476164"
data-ad-slot="7072194213"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 3, $content );
}
return $content;
}
// Parent Function that makes the magic happen
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
$closing_p = '</p>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
if ( $paragraph_id == $index + 1 ) {
$paragraphs[$index] .= $insertion;
}
}
return implode( '', $paragraphs );
}